QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#422451 | #964. Excluded Min | JohnAlfnov | RE | 1597ms | 382752kb | C++14 | 3.9kb | 2024-05-27 14:42:24 | 2024-05-27 14:42:24 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n,q,a[500005];
struct apple{
int l,r,wz;
bool operator<(const apple &other)const{
if(l==other.l)return r>other.r;
return l<other.l;
}
}e[500005];
int id[500005];
int ls[8000005],rs[8000005],tot=0;
int xz;
vector<int>gg[8500005];
int deg[8500005];
void addedge(int x,int y){
gg[x].emplace_back(y);++deg[y];
}
void add(int x,int y,int l,int r,int z){
if(l==r){
if(x)addedge(y+q,x+q);
addedge(y+q,xz);
return;
}
int mid=(l+r)>>1;
ls[y]=ls[x],rs[y]=rs[x];
if(z<=mid)add(ls[x],ls[y]=++tot,l,mid,z);
else add(rs[x],rs[y]=++tot,mid+1,r,z);
}
void query(int x,int l,int r,int ll,int rr){
if(l>=ll&&r<=rr){
addedge(xz,x+q);
return;
}
int mid=(l+r)>>1;
if(mid>=ll&&ls[x])query(ls[x],l,mid,ll,rr);
if(mid<rr&&rs[x])query(rs[x],mid+1,r,ll,rr);
}
#define M 500000
vector<int>g[500005];
int ans[500005];
int c[500005];
void addf(int x,int s){
while(x<=n){
c[x]+=s;
x+=x&-x;
}
}
int queryf(int x){
int ans=0;
while(x){
ans+=c[x];
x-=x&-x;
}
return ans;
}
int sm[1200005],s2[1200005],lz[1200005];
void pushdown(int o){
if(!lz[o])return;
sm[o<<1]+=lz[o],lz[o<<1]+=lz[o];
sm[o<<1|1]+=lz[o],lz[o<<1|1]+=lz[o];
lz[o]=0;
}
void build(int l,int r,int o){
if(l==r){
sm[o]=-1e9,s2[o]=l;
return;
}
int mid=(l+r)>>1;
build(l,mid,o<<1);
build(mid+1,r,o<<1|1);
if(sm[o<<1]>sm[o<<1|1])sm[o]=sm[o<<1],s2[o]=s2[o<<1];
else sm[o]=sm[o<<1|1],s2[o]=s2[o<<1|1];
}
void modify(int l,int r,int o,int x,int z){
if(l==r){
sm[o]=z;
return;
}
pushdown(o);
int mid=(l+r)>>1;
if(x<=mid)modify(l,mid,o<<1,x,z);
else modify(mid+1,r,o<<1|1,x,z);
if(sm[o<<1]>sm[o<<1|1])sm[o]=sm[o<<1],s2[o]=s2[o<<1];
else sm[o]=sm[o<<1|1],s2[o]=s2[o<<1|1];
}
void addd(int l,int r,int o,int ll,int rr,int s){
if(l>=ll&&r<=rr){
sm[o]+=s;lz[o]+=s;
return;
}
pushdown(o);
int mid=(l+r)>>1;
if(mid>=ll)addd(l,mid,o<<1,ll,rr,s);
if(mid<rr)addd(mid+1,r,o<<1|1,ll,rr,s);
if(sm[o<<1]>sm[o<<1|1])sm[o]=sm[o<<1],s2[o]=s2[o<<1];
else sm[o]=sm[o<<1|1],s2[o]=s2[o<<1|1];
}
set<pair<int,int>>se1,se2;
void jia(int z){
int zz=queryf(e[z].r)-queryf(e[z].l-1);
modify(1,q,1,z,zz);
se1.emplace(e[z].l,z);
se2.emplace(e[z].r,z);
}
queue<int>qu;
void jqq(int y){
for(auto cu:gg[y]){
--deg[cu];
if(!deg[cu]){
if(cu<=q){
jia(cu);
}else{
qu.emplace(cu);
}
}
}
if(y>q&&ls[y-q]){
int cu=ls[y-q]+q;
--deg[cu];
if(!deg[cu]){
if(cu<=q){
jia(cu);
}else{
qu.emplace(cu);
}
}
}
if(y>q&&rs[y-q]){
int cu=rs[y-q]+q;
--deg[cu];
if(!deg[cu]){
if(cu<=q){
jia(cu);
}else{
qu.emplace(cu);
}
}
}
}
int main(){
scanf("%d%d",&n,&q);
for(int i=1;i<=n;++i){
scanf("%d",&a[i]);
g[a[i]].emplace_back(i);
}
for(int i=1;i<=q;++i){
scanf("%d%d",&e[i].l,&e[i].r);
e[i].wz=i;
}
sort(e+1,e+q+1);
for(int i=q;i>=1;--i){
xz=i;
add(id[i+1],id[i]=++tot,1,n,e[i].r);
if(id[i+1])query(id[i+1],1,n,1,e[i].r);
}
for(int i=1;i<=tot;++i){
if(ls[i])++deg[ls[i]+q];
if(rs[i])++deg[rs[i]+q];
}
for(int i=1;i<=n;++i){
addf(i,1);
}
build(1,q,1);
for(int i=1;i<=tot+q;++i)if(!deg[i]){
if(i<=q){
jia(i);
}else{
qu.emplace(i);
}
}
while(qu.size()){
int y=qu.front();qu.pop();
jqq(y);
}
for(int an=M;an>=0;--an){
while(sm[1]>=an+1){
int t=s2[1];
se1.erase(make_pair(e[t].l,t));
se2.erase(make_pair(e[t].r,t));
ans[e[t].wz]=an+1;
modify(1,q,1,t,-1e9);
jqq(t);
while(qu.size()){
int y=qu.front();qu.pop();
jqq(y);
}
}
for(auto x:g[an]){
addf(x,-1);
auto t1=se2.lower_bound(make_pair(x,0));
auto t2=se1.lower_bound(make_pair(x+1,0));
if(t1!=se2.end()){
int L=(*t1).second;
int R=n;
if(t2!=se1.end())R=(*t2).second-1;
if(L<=R)addd(1,q,1,L,R,-1);
}
}
}
for(int i=1;i<=q;++i)printf("%d\n",ans[i]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 27ms
memory: 231200kb
input:
3 3 0 0 2 1 3 2 3 3 3
output:
3 1 0
result:
ok 3 number(s): "3 1 0"
Test #2:
score: 0
Accepted
time: 35ms
memory: 229112kb
input:
3 2 1 2 2 1 2 1 3
output:
0 3
result:
ok 2 number(s): "0 3"
Test #3:
score: 0
Accepted
time: 23ms
memory: 233180kb
input:
10 10 3 0 3 3 9 7 9 6 0 7 3 3 9 9 4 6 1 9 3 4 2 4 7 10 3 7 5 7 2 7
output:
0 1 0 5 0 1 1 0 0 1
result:
ok 10 numbers
Test #4:
score: 0
Accepted
time: 32ms
memory: 231204kb
input:
10 10 3 0 0 0 5 1 1 1 2 1 1 2 8 8 5 7 1 7 2 2 1 5 5 6 4 6 3 10 6 8
output:
1 0 2 7 1 4 0 2 8 3
result:
ok 10 numbers
Test #5:
score: 0
Accepted
time: 36ms
memory: 231448kb
input:
100 100 15 82 7 39 63 55 64 99 71 63 32 99 67 94 3 43 15 75 45 55 53 4 35 36 15 40 82 20 62 43 6 83 27 95 27 45 98 44 35 98 39 7 17 32 76 7 40 16 40 63 13 8 22 27 11 12 61 14 19 45 100 97 90 88 22 59 25 63 4 25 65 16 22 92 84 44 99 66 89 26 93 97 35 97 92 1 32 40 97 97 78 43 7 12 23 53 61 74 33 90 1...
output:
68 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 48 0 0 0 0 0 0 0 0 0 0 0 0 0 28 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
result:
ok 100 numbers
Test #6:
score: 0
Accepted
time: 36ms
memory: 231160kb
input:
100 100 17 86 33 8 11 27 8 11 13 9 3 43 11 23 26 42 44 12 44 12 15 0 75 51 72 5 49 2 40 57 24 47 39 42 4 5 6 52 3 2 42 19 62 33 24 22 16 69 4 33 44 70 29 11 2 2 58 9 6 10 25 10 33 26 17 3 14 0 48 7 48 51 0 39 54 37 14 9 3 85 18 4 25 9 2 0 39 8 17 13 25 45 10 39 12 18 9 5 66 6 13 89 10 90 42 67 43 52...
output:
76 80 0 0 18 1 18 1 5 5 1 1 22 11 0 15 0 59 5 56 1 80 0 1 1 21 0 61 22 11 0 3 8 15 40 1 8 81 71 20 2 0 60 0 60 31 0 59 0 0 0 28 0 21 1 7 5 0 31 0 76 28 0 0 27 1 23 0 1 27 1 0 0 1 0 5 63 52 2 43 73 1 86 0 61 0 27 2 30 5 31 1 0 14 59 27 1 1 67 63
result:
ok 100 numbers
Test #7:
score: 0
Accepted
time: 31ms
memory: 229100kb
input:
100 100 6 1 1 5 13 11 35 5 3 2 0 4 0 9 1 2 3 3 19 1 7 9 7 11 7 8 10 18 28 17 31 2 4 8 2 3 3 2 22 4 9 4 7 2 9 15 8 2 3 19 5 24 3 10 11 5 9 20 8 4 11 10 18 9 13 34 5 34 2 9 24 6 21 16 6 12 26 2 2 2 6 11 2 14 3 8 2 12 2 19 8 3 18 23 5 21 23 8 4 0 44 67 25 74 24 79 59 73 4 81 42 66 48 55 15 38 35 63 16 ...
output:
22 50 56 0 78 23 0 22 29 24 38 37 17 57 0 6 0 58 52 4 64 44 0 37 75 75 34 89 0 4 0 12 39 0 0 69 53 14 38 13 36 30 0 7 46 83 28 6 44 22 40 50 24 26 36 49 0 0 6 49 27 78 0 37 11 49 16 50 25 30 37 58 64 28 62 36 0 52 0 95 34 4 50 17 0 27 44 0 0 21 44 66 69 0 39 25 0 2 63 0
result:
ok 100 numbers
Test #8:
score: 0
Accepted
time: 27ms
memory: 231156kb
input:
100 100 0 1 0 1 0 1 1 1 0 2 1 1 2 0 1 1 0 3 0 0 0 0 0 0 0 0 1 2 2 0 0 0 0 1 0 0 1 2 0 0 1 0 0 3 0 1 0 0 3 0 0 0 1 1 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 2 0 0 0 4 0 1 1 0 1 0 2 2 0 0 1 41 53 31 36 78 99 60 86 1 67 3 92 89 92 60 70 42 56 42 46 39 84 40 66 9 27 75 78 33 94 17 53...
output:
13 6 22 27 67 90 3 11 15 5 46 27 19 4 62 37 84 35 53 4 47 95 55 63 24 39 22 51 67 21 55 36 24 16 33 74 4 16 63 81 41 14 3 54 6 40 36 33 29 32 14 60 13 17 73 44 34 2 14 79 59 13 75 72 31 10 22 57 23 37 74 2 6 6 38 5 4 62 66 22 33 0 23 21 12 54 75 6 8 16 37 36 3 53 63 18 67 60 31 19
result:
ok 100 numbers
Test #9:
score: 0
Accepted
time: 683ms
memory: 349856kb
input:
300000 300000 216504 101790 177261 84423 215788 67188 170620 125383 222808 149722 190483 152974 27524 172557 109218 201761 138030 177265 270417 244027 29296 13565 108388 270622 75102 137755 134081 21988 249714 268911 178911 39288 197287 232628 152784 226739 40134 213404 230781 181323 235763 55745 44...
output:
1 3 0 0 1 1 0 11 0 0 3 1 0 0 1 1 0 0 0 0 3 0 1 1 1 1 1 1 0 0 0 0 0 1 1 13 0 0 0 11 0 1 1 1 3 0 1 1 0 0 0 0 0 0 1 0 0 0 3 0 13 1 1 14 3 0 0 1 0 0 1 1 1 1 0 0 3 0 1 0 0 3 1 1 0 0 0 3 0 0 1 1 0 1 1 0 1 0 0 1 1 0 0 1 1 1 0 1 0 1 1 1 1 0 0 0 0 11 1 0 0 0 13 0 0 3 0 1 0 1 0 0 1 0 3 0 3 1 0 0 0 1 1 13 1 1 ...
result:
ok 300000 numbers
Test #10:
score: 0
Accepted
time: 961ms
memory: 346132kb
input:
300000 300000 59375 140115 159075 154436 141196 15338 197722 158230 143168 29542 129520 24443 86025 174147 79007 72481 119436 30645 76347 16689 86494 58226 52030 12421 82352 104631 29663 109785 14534 15981 14386 116251 72729 63907 160568 62881 49823 131557 73658 36095 152983 102029 30197 8451 6637 5...
output:
178459 3302 1 1 0 0 116568 0 184096 0 275466 0 176260 1 1 235740 1 0 224495 212359 151327 10 164683 0 122505 84233 244352 12836 205269 29938 21548 128221 1 0 1 1 258766 189984 224975 7 12935 0 79823 0 217416 193250 204170 178196 37490 0 1 0 8 156975 174553 0 92490 1 7 151697 1 164 0 213287 1 186571 ...
result:
ok 300000 numbers
Test #11:
score: 0
Accepted
time: 1121ms
memory: 349612kb
input:
300000 300000 13382 6122 36036 1752 43260 20658 29295 6934 24163 15277 26525 3000 90431 1780 14895 33643 79181 20791 14941 28678 20366 24408 26713 14036 58649 36147 56859 26178 20143 57439 6852 19586 38748 41652 986 22368 46087 20998 9508 42052 26443 17946 53822 1630 16047 4410 26131 6783 10049 8204...
output:
0 0 74615 230263 49091 155785 40039 245512 9 87064 215692 108066 41690 76887 0 47929 13625 94648 116990 2 1 146674 0 234901 48458 37669 2 206305 210550 0 2 136250 0 73532 241430 23763 94113 243203 271759 10704 2 193100 156845 153922 265442 0 121742 97647 133440 170932 107307 87796 149291 261163 0 81...
result:
ok 300000 numbers
Test #12:
score: 0
Accepted
time: 1132ms
memory: 342824kb
input:
300000 300000 693 15101 2105 3132 2823 4511 312 5151 69 3220 112 15836 5686 4016 4747 7996 97 304 8236 6602 413 818 2294 542 1239 1977 8768 3788 919 2330 651 507 6511 21404 1242 6052 1027 472 1046 608 2891 399 507 7798 4523 1092 94 255 7123 2493 2675 16852 1300 932 639 14840 665 2793 877 969 3090 17...
output:
108218 242349 72761 127143 151481 169916 95612 70846 31733 210337 90038 184672 27459 181773 26560 93495 0 108954 147314 69487 104909 176794 24826 76628 18027 181289 196727 202345 132323 789 24765 104826 19945 58405 276481 32405 21870 5852 108034 162998 24368 77991 134070 10340 79673 54012 18248 0 86...
result:
ok 300000 numbers
Test #13:
score: 0
Accepted
time: 547ms
memory: 382752kb
input:
400000 400000 84329 284144 8196 328223 350667 119044 61607 111375 149099 295090 191250 2984 2837 7919 395586 118583 79852 220759 93838 163172 170285 111947 348858 76246 158367 325491 360832 23094 345883 64402 68588 38489 36833 25877 388546 240645 163753 282542 293242 288593 205050 193517 232308 2769...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 400000 numbers
Test #14:
score: 0
Accepted
time: 1304ms
memory: 382116kb
input:
400000 400000 18486 122948 4137 14655 54438 228799 295881 106438 50815 201228 52969 237859 125326 12791 261129 91102 64978 32041 132228 85743 210398 120735 187473 249388 27933 19782 179803 111622 103176 341 26733 1933 135306 165570 269738 1527 215310 172587 51120 22514 261669 158503 184320 91539 986...
output:
0 62201 4 0 12 1 149330 153206 264801 137132 277605 0 17 191339 83865 92939 144238 185422 259663 0 0 116466 461 0 91 143227 0 0 2 0 153978 20 0 12 235071 133168 0 85 191321 0 0 72798 0 0 262584 191216 0 270135 2307 5 328156 290867 0 0 104005 12 235848 0 0 0 65 0 0 0 140246 0 116243 0 0 179579 82742 ...
result:
ok 400000 numbers
Test #15:
score: 0
Accepted
time: 1583ms
memory: 379736kb
input:
400000 400000 4230 8875 14228 68140 13626 5962 49017 7168 40307 13812 1964 8548 36045 5418 8513 22358 42641 44547 14800 34379 7176 20841 15146 4959 27352 66386 1982 72275 15171 38548 5215 16247 15759 14047 101799 39722 51238 20202 23684 5307 3884 2280 23172 23320 39097 2227 48427 23097 1262 23346 33...
output:
39692 115006 66652 174773 248161 147529 163061 55249 2 276174 24001 331244 201834 278983 56324 208994 260118 199479 152056 141187 82281 1 67141 306318 203228 184782 229826 169471 118739 0 199767 363451 0 351932 0 74373 167703 71598 207200 166071 26722 271364 195830 113466 281136 182903 383788 101561...
result:
ok 400000 numbers
Test #16:
score: 0
Accepted
time: 1597ms
memory: 378536kb
input:
400000 400000 8349 3356 2462 5033 3722 9245 1515 14134 2785 1049 7271 3160 1932 4886 707 4013 1703 1740 5150 6756 2242 864 808 3715 2459 560 2100 74 1323 1191 5196 243 6096 224 4749 1599 4253 2181 674 3239 2183 1064 494 611 1290 2518 4893 2511 1646 4480 5308 7227 1251 8801 2856 2438 6038 4149 2111 1...
output:
254539 332051 348302 337539 264574 26680 108859 369802 354144 271555 6761 74689 134044 84380 336750 318514 92694 258364 177509 185374 267641 11499 120477 114594 81129 119715 12622 246956 7044 172251 146211 53586 160423 328652 86713 120234 1 332759 44517 94408 114688 59086 53329 2852 52545 56392 2411...
result:
ok 400000 numbers
Test #17:
score: -100
Runtime Error
input:
500000 500000 429640 265052 139201 292952 485277 448373 374047 197183 296565 140106 191815 352449 300184 342644 482687 114114 22085 463647 438259 4048 411430 387773 110813 182238 41281 490781 87834 201747 340347 359872 235681 415850 376481 396340 244935 32773 286463 50453 255957 96096 252296 331225 ...