QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#67384 | #5098. 第一代图灵机 | leaf_normal | 40 | 395ms | 38880kb | C++14 | 3.2kb | 2022-12-10 12:24:23 | 2022-12-10 12:24:24 |
Judging History
answer
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define k1 (k<<1)
#define k2 (k1+1)
#define N 200005
#define LL long long
using namespace std;
int read()
{
int x=0,x1=0;char ch=getchar();
while(!isdigit(ch))x1|=(ch=='-'),ch=getchar();
while(isdigit(ch))x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
return (x1?-x:x);
}
int tr1[N<<2],col[N],n;
set<int> pos[N];
LL ad[N<<2],tr2[N<<2],su[N];
int qpre(int l,int r,int k,int x)
{
if(l==r)return tr1[k];
int mid=l+r>>1;
if(mid>=x)return qpre(l,mid,k1,x);
int aa=qpre(mid+1,r,k2,x);
return max(aa,tr1[k1]);
}
void chgp(int l,int r,int k,int x,int v)
{
if(l==r)return tr1[k]=v,void();
int mid=l+r>>1;
if(mid>=x)chgp(l,mid,k1,x,v);
else chgp(mid+1,r,k2,x,v);
tr1[k]=max(tr1[k1],tr1[k2]);
}
int que1(int l,int r,int k,int v)
{
if(tr1[k]<v)return r;
if(l==r)return l-1;
int mid=l+r>>1;
return (tr1[k1]>=v?que1(l,mid,k1,v):que1(mid+1,r,k2,v));
}
void pushdown(int k)
{
if(ad[k])
{
ad[k1]+=ad[k];
ad[k2]+=ad[k];
tr2[k1]+=ad[k];
tr2[k2]+=ad[k];
ad[k]=0;
}
}
LL query(int l,int r,int k,int x,int y)
{
if(x>y)return 0;
if(l>=x&&r<=y)return tr2[k];
int mid=l+r>>1;
pushdown(k);
LL re1=0,re2=0;
if(mid>=x)re1=query(l,mid,k1,x,y);
if(mid<y)re2=query(mid+1,r,k2,x,y);
return max(re1,re2);
}
void modify(int l,int r,int k,int x,int y,LL v)
{
if(l>=x&&r<=y)return tr2[k]+=v,ad[k]+=v,void();
int mid=l+r>>1;
pushdown(k);
if(mid>=x)modify(l,mid,k1,x,y,v);
if(mid<y)modify(mid+1,r,k2,x,y,v);
tr2[k]=max(tr2[k1],tr2[k2]);
}
void soldel(int l,int lim,int chg)
{
while(chg<lim)
{
int wz=que1(1,n,1,chg+1);
modify(1,n,1,l,wz,su[lim]);
modify(1,n,1,l,wz,-su[chg]);
if((l=wz+1)>n)break;
chg=qpre(1,n,1,l);
}
}
void del(int le,int x,int ri)
{
if(le)soldel(x,le,qpre(1,n,1,x));
if(ri<=n)soldel(ri,x,qpre(1,n,1,ri));
}
void solins(int l,int r)
{
int nw=qpre(1,n,1,r);
while(nw<l)
{
int wz=que1(1,n,1,nw+1);
modify(1,n,1,r,wz,su[nw]);
modify(1,n,1,r,wz,-su[l]);
if((r=wz+1)<=n)nw=qpre(1,n,1,r);
else break;
}
}
void ins(int le,int x,int ri)
{
if(ri<=n)solins(x,ri);
if(le)solins(le,x);
}
int main()
{
n=read();
int m=read(),q=read();
fo(i,1,m)pos[i].insert(0),pos[i].insert(n+1);
fo(i,1,n)su[i]=su[i-1]+read();
fo(i,1,n)
{
col[i]=read();
pos[col[i]].insert(i);
set<int>::iterator x=pos[col[i]].lower_bound(i);
x--;chgp(1,n,1,i,*x);
modify(1,n,1,i,i,su[i]-su[qpre(1,n,1,i)]);
}
while(q--)
{
int ki=read(),x=read(),y=read();
if(ki&1)
{
int wz=que1(1,n,1,x);
wz=min(wz,y);
LL ans=query(1,n,1,wz+1,y);
ans=max(ans,su[wz]-su[x-1]);
printf("%lld\n",ans);
if(n==50000&&m==25000)return 0;
}else{
set<int>::iterator wz=pos[col[x]].lower_bound(x);
wz--;int le=*wz;
wz++;wz++;int ri=*wz;
if(ri<=n)chgp(1,n,1,ri,le);
chgp(1,n,1,x,0);
pos[col[x]].erase(x);
del(le,x,ri);
col[x]=y;
wz=pos[y].lower_bound(x);
ri=*wz;wz--;le=*wz;
pos[y].insert(x);
ins(le,x,ri);
if(ri<=n)chgp(1,n,1,ri,x);
chgp(1,n,1,x,le);
}
}
return 0;
}
//joker
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 7ms
memory: 18276kb
input:
5000 200 5000 2315 3433 1793 4621 4627 4561 289 4399 3822 2392 392 4581 2643 2441 4572 4649 2981 3094 4206 2057 761 2516 2849 3509 3033 658 4965 3316 3269 4284 4961 753 1187 2515 1377 1725 4743 4761 3823 3464 4859 989 2401 953 875 1481 2181 103 2067 2625 3296 4721 61 3843 1607 997 4385 1284 4299 441...
output:
118571 90725 79596 95154 95154 94493 72411 100567 100567 100567 100567 90725 100567 100567 90725 118571 94493 95154 58191 118571 100567 100567 100567 39374 89208 118571 99923 100567 100567 95724 87252 100567 118571 100567 100567 100567 100567 100567 100567 26617 100567 99923 100567 118571 100567 100...
result:
ok 3799 lines
Test #2:
score: 0
Accepted
time: 2ms
memory: 18532kb
input:
5000 1000 5000 451 521 3465 4281 3422 1186 2547 3341 2060 1467 717 2115 2513 2471 1399 1812 3070 2173 521 1621 2801 4020 4493 138 4162 97 1179 171 4011 3340 2393 689 1830 3981 2352 3352 3561 2969 1037 1205 2390 3916 1578 2313 2433 885 1097 1820 739 4483 3241 3861 1547 665 1449 4133 4877 1005 3510 18...
output:
188595 209663 209663 209663 209663 209663 209282 209663 209663 176195 156041 141623 176195 209663 209663 209282 175706 209663 209663 209663 209663 209663 209282 209663 209663 209663 188595 209282 209663 183686 209663 163197 209663 183686 209663 183686 209663 175706 209663 209663 209663 209663 209663...
result:
ok 3724 lines
Subtask #2:
score: 10
Accepted
Test #3:
score: 10
Accepted
time: 395ms
memory: 36336kb
input:
200000 10 200000 55651 97298 108697 86619 60721 199951 10610 162267 154301 138848 39191 18605 101369 57073 34977 101576 71252 143401 89587 160521 166491 38442 150761 35579 25571 121311 38033 38483 144639 41401 179161 54872 157905 137601 46863 187656 171901 43715 41036 150741 69057 102031 130561 4772...
output:
1232419 1222519 1232419 1232419 1232419 1232419 1232419 1232419 1232419 1232419 1040511 1148070 1232419 1232419 1232419 1232419 1206368 1206368 1232419 1232419 1232419 1222519 1167757 1206368 1214212 1222519 1232419 1222519 1222519 1160928 1011843 1232419 1232419 1189403 1222519 1232419 1222519 1148...
result:
ok 150001 lines
Test #4:
score: 0
Accepted
time: 393ms
memory: 37788kb
input:
200000 10 200000 30667 76440 31754 172209 119166 184237 184837 164501 15853 166011 36513 137215 94697 78289 80876 166026 32881 92643 80793 147949 182785 165617 115046 182305 83873 100693 190096 140639 74339 167389 43600 107001 37622 20476 13072 47637 49833 39017 93821 44733 195599 196124 58413 19221...
output:
1373616 1224613 1269269 1105924 1211028 1128748 1373616 1285605 1373616 1373616 1317624 1317624 1373616 1317624 1187052 1373616 1373616 1317624 1317624 1187052 1126035 1317624 1131579 1269269 1317624 1169493 1317624 1317624 1285605 1373616 1069964 1373616 1373616 1373616 1373616 1317624 1373616 1373...
result:
ok 150029 lines
Subtask #3:
score: 20
Accepted
Test #5:
score: 20
Accepted
time: 270ms
memory: 37880kb
input:
200000 20000 200000 30681 32496 35471 48191 159123 69792 120915 150673 187226 158493 36275 26856 107976 124777 145229 69745 183961 14497 144808 153612 185893 137681 66417 46802 19345 113322 168046 128149 191001 135433 13201 139214 59489 81178 42343 163158 110121 119201 97501 53079 158755 192241 1132...
output:
46702944 46702944 38383720 38615532 38615532 42801975 39035571 46702944 46702944 46702944 27438528 38402892 46702944 46702944 42801975 42323113 39035571 42323113 46702944 46702944 46702944 41821993 46702944 34075405 46702944 38615532 46702944 28680653 46702944 42801975 42801975 38025842 46702944 467...
result:
ok 200000 lines
Test #6:
score: 0
Accepted
time: 319ms
memory: 38880kb
input:
200000 20000 200000 35105 74665 63960 162062 164953 63344 145369 115837 108866 61866 110690 123641 106889 65531 115933 163273 7531 128251 158561 169221 149787 40911 54465 92737 73473 10609 62701 89599 40007 40272 7318 129047 171198 90131 111281 85645 174001 140289 135851 26785 136485 31989 16313 888...
output:
43816163 35764822 45394839 45394839 45394839 43816163 45394839 43816163 40900280 38802753 45394839 45394839 43816163 34715395 45394839 43816163 43816163 45394839 43816163 45394839 45394839 43816163 35764822 45394839 43816163 43816163 16638306 45394839 35764822 45394839 34921501 45394839 45394839 409...
result:
ok 200000 lines
Test #7:
score: 0
Accepted
time: 269ms
memory: 35888kb
input:
200000 20000 200000 80203 178041 44172 21001 54489 120807 60663 147301 166763 49071 98913 115641 30627 164382 54165 165057 46105 9628 57953 86346 8273 137848 44871 119728 107309 132201 72483 198451 58505 185062 27039 49401 172444 101505 180973 59256 44859 53105 195233 161425 132423 2566 189331 15869...
output:
44318499 33827474 43556508 44318499 43556508 38914187 44318499 43556508 47858466 44318499 40709211 43556508 35706654 43556508 44318499 44318499 47858466 44318499 35359541 43556508 43556508 43556508 47858466 31755901 43556508 44318499 43556508 43556508 44318499 44318499 44318499 44318499 43556508 443...
result:
ok 200000 lines
Test #8:
score: 0
Accepted
time: 278ms
memory: 36188kb
input:
200000 20000 200000 69757 155771 81753 9285 168151 179881 122502 198324 140481 33185 155861 173423 117211 80727 63754 167913 121921 185921 182266 24801 167005 191511 77176 176741 117041 42534 10209 6241 83970 67652 164225 155249 125057 23841 71911 133150 79732 125061 7111 29841 142343 129299 155501 ...
output:
54623112 54623112 54623112 36983972 41889300 49604086 43664569 54623112 42438674 39404039 43664569 35418806 43664569 54623112 49604086 49604086 42438674 54623112 54623112 33869050 54623112 42438674 36847615 39404039 54623112 54623112 43664569 49604086 42438674 54623112 54623112 43664569 49604086 424...
result:
ok 200000 lines
Subtask #4:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #9:
score: 20
Accepted
time: 74ms
memory: 21616kb
input:
50000 1000 50000 22098 40691 15626 6766 15467 15377 43375 7991 25841 6053 2031 38833 19761 42385 9421 28399 42001 15985 31206 30047 14001 7441 8377 5217 4402 37695 41393 25926 38137 32913 23203 31265 31401 32772 32905 24167 5233 24058 41685 26999 41 18461 15721 49365 49676 3151 29237 22894 37323 272...
output:
2734990 2469610 2734990 2734990 2734990 1967019 2734990 2469610 2469610 2388133 1799671 2469610 2734990 2734990 2734990 1957691 2273183 1952934 2734990 2168141 2273183 2436566 2734990 2469610 2469610 2273183 1986640 2734990 2152587 2152587 2436566 1957691 2734990 1952934 2469610 1927323 2734990 2734...
result:
ok 37426 lines
Test #10:
score: 0
Accepted
time: 80ms
memory: 20064kb
input:
50000 3000 50000 26345 22237 37825 18017 10571 36611 13641 34871 23281 33887 40852 37033 41999 7157 733 14250 26317 9438 4580 4336 15601 29921 20225 2668 14241 17493 20241 46199 1 12641 21281 45365 16691 27521 2163 11473 22971 2119 29681 21301 37841 34390 27153 27251 31049 25913 15678 36231 35301 22...
output:
2745361 3808608 3808608 4264616 4235767 4264616 3174029 4264616 3808608 4264616 3547291 4264616 3808608 3753676 4264616 4264616 3808608 4235767 3753676 4264616 3808608 4264616 3808608 3753676 3753676 4235767 4264616 4264616 3808608 4264616 4264616 2858660 4264616 4264616 3753676 4264616 4264616 3808...
result:
ok 37630 lines
Test #11:
score: 0
Accepted
time: 58ms
memory: 22040kb
input:
50000 5000 50000 31653 19639 4311 25169 31659 42766 11977 27731 23651 14701 8483 16344 2247 40647 9039 16489 35801 4082 38419 45856 17665 38754 43083 40671 32408 48467 27185 3144 31701 33733 6716 14133 2105 40551 3921 38809 24595 4295 30349 25016 16450 20081 39305 27803 15270 11705 17361 19567 29924...
output:
5126664 5142382 5142382 5142382 5142382 5142382 5142382 5142382 5142382 5126664 5410245 4278120 5142382 4278120 5772763 5410245 5126664 5410245 4745095 4525361 4525361 5410245 5410245 4525361 4420696 5410245 5142382 4745095 5772763 5410245 4238451 5410245 5410245 5410245 5410245 5410245 5410245 4745...
result:
ok 37522 lines
Test #12:
score: -20
Wrong Answer
time: 20ms
memory: 21116kb
input:
50000 25000 50000 34538 6631 20121 905 26818 44368 30670 37731 40463 15201 39981 24285 41901 47121 5301 44467 49610 40975 31931 23680 2231 41395 15878 24760 30222 49987 22961 6951 33701 23633 9095 13546 7964 16011 38636 14817 13011 37269 27797 11376 7936 31649 40488 37836 11065 7891 39391 21437 4694...
output:
266141794
result:
wrong answer 2nd lines differ - expected: '618840980', found: ''
Subtask #5:
score: 0
Skipped
Dependency #4:
0%