ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#199524 | #3464. Mex问题 | LDM0116 | 100 | 4436ms | 15196kb | C++ | 2.0kb | 2023-12-17 09:49:00 | 2023-12-17 12:13:49 |
answer
#include<bits/stdc++.h>
#define ll long long
#define gc() (p1==p2&&(p2=(p1=b)+fread(b,1,n,stdin),p1==p2)?EOF:*p1++)
using namespace std;
namespace r{
const int n=1000000;
char *p1,*p2,b[n];
inline int read(){
int x=0,f=1;
char c=gc();
while(!isdigit(c)){
if(c==45) f=-1;
c=gc();
}
while(isdigit(c)){
x=(x<<1)+(x<<3)+c-'0';
c=gc();
}
return x*f;
}
}
using namespace r;
namespace w{
const int s=1000000;
char b[s];
int cnt=0;
inline void write(int x){
if(x<0){
x=-x;
b[cnt++]=45;
if(cnt==s) fwrite(b,1,cnt,stdout),cnt=0;
}
if(x>9) write(x/10);
b[cnt++]=(x%10)|48;
if(cnt==s) fwrite(b,1,cnt,stdout),cnt=0;
}
inline void space(){
b[cnt++]=' ';
if(cnt==s) fwrite(b,1,cnt,stdout),cnt=0;
}
inline void endl(){
b[cnt++]='\n';
if(cnt==s) fwrite(b,1,cnt,stdout),cnt=0;
}
inline void show(){
if(cnt) fwrite(b,1,cnt,stdout),cnt=0;
}
}
using namespace w;
namespace ldm{
int n,q,v[1000001],ans;
struct node{
int minn;
}a[4000001];
inline void pushup(int x){
a[x].minn=min(a[x<<1].minn,a[x<<1|1].minn);
}
inline void modify(int x,int l,int r,int k,int v){
if(r<k||l>k) return;
if(l==r){
a[x].minn=v;
return;
}
int mid=(l+r)>>1;
modify(x<<1,l,mid,k,v);
modify(x<<1|1,mid+1,r,k,v);
pushup(x);
}
inline void query(int x,int l,int r,int L,int R){
if(r<L||l>R||l>r) return;
if(l>=L&&r<=R){
ans=min(ans,a[x].minn);
return;
}
int mid=(l+r)>>1;
query(x<<1,l,mid,L,R);
query(x<<1|1,mid+1,r,L,R);
}
int main(){
n=read(),q=read();
for(int i=1;i<=n;i++){
v[i]=read();
modify(1,1,n,i,v[i]);
}
while(q--){
int c=read(),l=read(),r=read();
if(c==1){
swap(v[l],v[r]);
modify(1,1,n,l,v[l]);
modify(1,1,n,r,v[r]);
}else{
ans=0x3f3f3f3f;
query(1,1,n,1,l-1);
query(1,1,n,r+1,n);
if(ans==0x3f3f3f3f){
write(n);
}else{
write(ans);
}
endl();
}
}
show();
return 0;
}
}
int main(){
ldm::main();
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 1ms
memory: 1176kb
input:
1000 1000 766 551 229 619 16 792 855 602 918 959 379 858 777 503 252 449 473 238 359 703 930 874 444...
output:
211 382 766 211 1000 551 16 47 766 551 1000 551 382 766 229 211 551 551 1000 551 766 766 211 1000 55...
result:
ok 473 lines
Test #2:
score: 10
Accepted
time: 0ms
memory: 1176kb
input:
1000 1000 979 835 871 109 874 446 706 581 33 808 267 662 295 702 793 375 127 938 338 340 352 431 539...
output:
835 835 109 482 482 547 547 9 517 835 517 109 547 547 517 835 547 517 4 547 547 547 4 547 4 547 547 ...
result:
ok 500 lines
Test #3:
score: 10
Accepted
time: 0ms
memory: 1176kb
input:
1000 1000 152 958 925 477 38 77 289 947 154 490 267 914 814 993 374 858 450 692 792 899 316 115 341 ...
output:
502 1000 152 1000 502 1000 1000 38 152 1000 502 672 1000 1000 502 502 1000 1000 1000 672 672 672 100...
result:
ok 516 lines
Test #4:
score: 10
Accepted
time: 774ms
memory: 15196kb
input:
1000000 1000000 416632 951954 346607 668902 615191 265616 312582 30395 835755 866377 515388 538995 6...
output:
0 0 0 0 1 0 0 1 0 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 0 0 ...
result:
ok 499975 lines
Test #5:
score: 10
Accepted
time: 759ms
memory: 15196kb
input:
1000000 1000000 108748 877565 196157 720468 129802 600075 317321 799786 665963 638373 510469 901108 ...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 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 1 0 0 0 0 0 1 1 6 ...
result:
ok 499969 lines
Test #6:
score: 10
Accepted
time: 742ms
memory: 15196kb
input:
1000000 1000000 812407 150933 396889 408364 72596 793626 731766 831633 169527 521479 50208 950746 47...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 1 1 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 7 0 1 0 2 0 7 0 0 3 ...
result:
ok 499952 lines
Test #7:
score: 10
Accepted
time: 521ms
memory: 15196kb
input:
999998 1000000 496742 1903 386521 847417 168428 380343 791167 240576 271414 613096 192711 723079 497...
output:
496742 496742 846822 846822 496742 846822 496742 846822 496742 846822 496742 846822 496742 999998 99...
result:
ok 499556 lines
Test #8:
score: 10
Accepted
time: 535ms
memory: 15196kb
input:
1000000 1000000 137393 664239 178477 745998 955585 221661 631802 12887 408835 943141 907351 214221 3...
output:
1000000 1000000 137393 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 10000...
result:
ok 500201 lines
Test #9:
score: 10
Accepted
time: 538ms
memory: 15192kb
input:
999998 1000000 487858 189435 425747 744974 571986 20129 489577 661897 906159 864589 145564 153617 27...
output:
999998 189435 999998 487858 999998 189435 487858 999998 999998 189435 189435 999998 999998 999998 99...
result:
ok 499608 lines
Test #10:
score: 10
Accepted
time: 566ms
memory: 15196kb
input:
999999 1000000 178622 257725 504698 723327 640246 10648 929245 508226 572943 464286 88720 809444 889...
output:
999999 759507 178622 178622 178622 759507 759507 178622 999999 759507 759507 759507 759507 759507 75...
result:
ok 499620 lines
Extra Test:
score: 0
Extra Test Passed