NOIp2018集训test-10-24(am&pm)

李巨连续AK三场了,我跟南瓜打赌李巨连续AK七场,南瓜赌李巨连续AK五场。

DAY1

T1 qu

按题意拿stack,queue和priority_que模拟即可。特判没有元素却要取出的情况。

T2 ming

贪心发现ddl越小的任务越早完成越好,排序更新答案即可。

T3 zi

可能是昨天看了虚树我脑子不太好用,思维僵化的厉害,打算用虚树搞这道题,然后写了180+,连样例都懒得测知道根本过不了交了个暴力,结果暴力还有70。50min270pt+2h10min0pt。

实际上并不想需要虚树啊,我老想着怎么递推我tm就不能递归吗,递归然后记忆化只有那么好写了。

 1 //Achen
 2 #include<bits/stdc++.h>
 3 #define For(i,a,b) for(int i=(a);i<=(b);i++)
 4 #define Rep(i,a,b) for(int i=(a);i>=(b);i--)
 5 #define Formylove return 0
 6 const int N=67,p=1e9+7;
 7 typedef long long LL;
 8 typedef double db;
 9 using namespace std;
10 int m;
11 LL T[N],sz[N],a[N],b[N],c[N],d[N],l[N];
12 
13 template<typename T> void read(T &x) {
14     char ch=getchar(); x=0; T f=1;
15     while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
16     if(ch=='-') f=-1,ch=getchar();
17     for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f;
18 }
19 
20 #define pr pair<int,LL>
21 #define Pr pair<pr,LL>
22 #define MP make_pair
23 #define se second
24 #define fi first
25 
26 map<Pr,LL>D;
27 LL get_D(int i,LL x,LL y) {
28     if(x==y) return 0LL;
29     LL rs=0;
30     if(x>y) swap(x,y);
31     if(D[MP(MP(i,x),y)]) return D[MP(MP(i,x),y)];
32     if(x<=sz[a[i]]&&y<=sz[a[i]]) rs=get_D(a[i],x,y);
33     else if(x>sz[a[i]]&&y>sz[a[i]]) rs=get_D(b[i],x-sz[a[i]],y-sz[a[i]]);
34     else rs=(get_D(a[i],x,c[i])+get_D(b[i],y-sz[a[i]],d[i])+l[i])%p;
35     D[MP(MP(i,x),y)]=rs; return rs;
36 }
37 
38 map<pr,LL>A;
39 LL get_A(int i,LL x) {
40     if(sz[i]==1) return 0LL;
41     LL rs=0;
42     if(A[MP(i,x)]) return A[MP(i,x)];
43     if(x<=sz[a[i]]) rs=(get_A(a[i],x)+get_A(b[i],d[i])+sz[b[i]]*(l[i]+get_D(a[i],c[i],x))%p)%p;
44     else rs=(get_A(b[i],x-sz[a[i]])+get_A(a[i],c[i])+sz[a[i]]*(l[i]+get_D(b[i],d[i],x-sz[a[i]]))%p)%p;
45     A[MP(i,x)]=rs; return rs;
46 }
47 
48 #define ANS
49 int main() {
50 #ifdef ANS
51     freopen("zi.in","r",stdin); 
52     freopen("zi.out","w",stdout);
53 #endif
54     read(m);
55     sz[0]=1;
56     For(i,1,m) {
57         read(a[i]); read(b[i]);
58         read(c[i]); read(d[i]); 
59         c[i]+=1; d[i]+=1; read(l[i]);
60         sz[i]=sz[a[i]]+sz[b[i]];
61         T[i]=(T[a[i]]+T[b[i]]+sz[a[i]]*sz[b[i]]%p*l[i]%p+get_A(a[i],c[i])*sz[b[i]]%p+get_A(b[i],d[i])*sz[a[i]]%p)%p;
62     }
63     For(i,1,m) printf("%lld\n",T[i]);
64     Formylove;
65 }
View Code

 

DAY2

T1 hao

这题数据出锅了吧,说好的一开始没有连着的实际上有而且不能被消去,这样实际上的消的效果就有多种可能了题意描述并不清楚。

一个坑点是读入字符串不能用scanf因为会有空串。

  1 //Achen
  2 #include<bits/stdc++.h>
  3 #define For(i,a,b) for(int i=(a);i<=(b);i++)
  4 #define Rep(i,a,b) for(int i=(a);i>=(b);i--)
  5 #define Formylove return 0
  6 const int N=4e3+7;
  7 typedef long long LL;
  8 typedef double db;
  9 using namespace std;
 10 int n,head,pr[N],nxt[N],tot;
 11 char a[N],s[N],o[5];
 12 
 13 template<typename T> void read(T &x) {
 14     char ch=getchar(); x=0; T f=1;
 15     while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
 16     if(ch=='-') f=-1,ch=getchar();
 17     for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f;
 18 }
 19 
 20 void del(int x) {
 21     int cnt=1;
 22     char bs=s[x];
 23     if(pr[x]&&s[pr[x]]==bs) {
 24         cnt++;
 25         if(pr[pr[x]]&&s[pr[pr[x]]]==bs) cnt++;
 26     }
 27     if(nxt[x]&&s[nxt[x]]==bs) {
 28         cnt++;
 29         if(nxt[nxt[x]]&&s[nxt[nxt[x]]]==bs) cnt++;
 30     }
 31     if(cnt<3) return ;
 32     while(x&&s[x]==bs) {
 33         if(x==head) {
 34             pr[nxt[x]]=0;
 35             head=nxt[x];
 36             x=nxt[x];
 37         }
 38         else {
 39             if(nxt[x]) pr[nxt[x]]=pr[x];
 40             nxt[pr[x]]=nxt[x];
 41             if(s[pr[x]]==bs) x=pr[x];
 42             else x=nxt[x];
 43         }
 44     }
 45     if(x) del(x);
 46 }
 47 
 48 void insert(int pos,char o,int f) {
 49     int x=head,y=++tot;
 50     s[y]=o;
 51     if(!pos) {
 52         nxt[y]=head;
 53         if(head) pr[head]=y;
 54         head=y;
 55     }
 56     else {
 57         For(i,1,pos-1) x=nxt[x];
 58         if(nxt[x]) {
 59             pr[nxt[x]]=y;
 60             nxt[y]=nxt[x];
 61         }
 62         nxt[x]=y; pr[y]=x;
 63     }
 64     if(f) del(y);
 65 }
 66 
 67 void print(int x) {
 68     if(!x) { puts(""); return; }
 69     putchar(s[x]);
 70     print(nxt[x]);
 71 }
 72 
 73 int m=0;
 74 void scan() {
 75     char ch=getchar();
 76     for(;;) {
 77         if(ch=='\n'||ch=='\r') break;
 78         a[m++]=ch;
 79         ch=getchar();
 80     }
 81 }
 82 
 83 #define ANS
 84 int main() {
 85 #ifdef ANS
 86     freopen("hao.in","r",stdin);
 87     freopen("hao.out","w",stdout);
 88 #endif
 89     scan();
 90     For(i,0,m-1) insert(i,a[i],0);
 91     read(n);
 92     For(cs,1,n) {
 93         int pos;
 94         read(pos);
 95         scanf("%s",o);
 96         insert(pos,o[0],1);
 97         if(!head) puts("-");
 98         else print(head);
 99     }
100     Formylove;
101 }
View Code

 

T2 kun

维护后缀最大值用栈贪心即可。好像学过栈的人都会吧。

 

T3 nan

考过的原题啊。发现答案是i*f[i]的前缀和,按f[i]分块地计算一下就好了。跟之前那题唯一的差别是多个询问所以要离线一起做。

 1 //Achen
 2 #include<bits/stdc++.h>
 3 #define For(i,a,b) for(int i=(a);i<=(b);i++)
 4 #define Rep(i,a,b) for(int i=(a);i>=(b);i--)
 5 #define Formylove return 0
 6 const int N=1e6,p=1e9+7;
 7 typedef long long LL;
 8 typedef double db;
 9 using namespace std;
10 int f[N+7],T,n;
11 LL ans=0;
12 
13 template<typename T> void read(T &x) {
14     char ch=getchar(); x=0; T f=1;
15     while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
16     if(ch=='-') f=-1,ch=getchar();
17     for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f;
18 }
19 
20 LL dc(LL a,LL b) { 
21     if((a+b)%2) return (b-a+1)/2%p*((a+b)%p)%p; 
22     else return (a+b)/2%p*((b-a+1)%p)%p;
23 }
24 
25 struct qs {
26     int n,id;
27     friend bool operator <(const qs&A,const qs&B) {
28         return A.n<B.n;
29     }
30 }q[N];
31 LL rs[N];
32 
33 #define ANS
34 int main() {
35 #ifdef ANS
36     freopen("nan.in","r",stdin);
37     freopen("nan.out","w",stdout);
38 #endif
39     f[1]=1; f[2]=2; f[3]=2;
40     int now=3;
41     for(int i=3;;i++) {
42         For(j,1,f[i]) {
43             f[now+j]=i;
44             if(now+j==N) break;
45         }
46         now+=f[i];
47         if(now>=N) {
48             now=N; break; 
49         }
50     }
51     read(T);
52     For(i,1,T) {
53         read(q[i].n);
54         q[i].id=i;
55     }
56     sort(q+1,q+T+1);
57     int nq=1; now=0;
58     ans=0;
59     for(int i=1;;i++) {
60         while(nq<=T&&now+f[i]>=q[nq].n) {
61             rs[q[nq].id]=(ans+dc(now+1,q[nq].n)*i%p)%p;
62             nq++;
63         }
64         if(nq>T) break;
65         ans=(ans+dc(now+1,now+f[i])*i%p)%p;
66         now+=f[i];    
67     }
68     For(i,1,T) printf("%lld\n",rs[i]);
69     //cerr<<clock()<<endl;
70     Formylove;
71 }
View Code

 

posted @ 2018-10-24 20:06  啊宸  阅读(225)  评论(0编辑  收藏  举报