ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#200156 | #553. 序列 | yizhiming | 100 | 3490ms | 6824kb | C++ | 1.5kb | 2023-12-30 08:02:44 | 2023-12-30 12:03:25 |
answer
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
using namespace std;
int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
const int N = 2e5+5;
int n,m;
int bel[N],cnt[N],a[N],lsh[N];
int L[N],R[N],ans[N];
struct aa{
int l,r,id;
bool operator<(const aa&x)const{
if(bel[l]==bel[x.l]){
return r<x.r;
}else{
return bel[l]<bel[x.l];
}
}
}node[N];
int sum;
void upd(int x){
if(cnt[a[x]]&1){
sum++;
}
cnt[a[x]]++;
}
void del(int x){
cnt[a[x]]--;
if(cnt[a[x]]&1){
sum--;
}
}
int main(){
n = read();m = read();
for(int i=1;i<=n;i++){
a[i] = read();
lsh[i] = a[i];
}
sort(lsh+1,lsh+1+n);
int z = unique(lsh+1,lsh+1+n)-lsh-1;
for(int i=1;i<=n;i++){
a[i] = lower_bound(lsh+1,lsh+1+z,a[i])-lsh;
}
int sz = sqrt(n);
for(int i=1;i<=n;i++){
bel[i] = (i-1)/sz+1;
if(!L[bel[i]]){
L[bel[i]] = i;
}
R[bel[i]] = i;
}
for(int i=1;i<=m;i++){
int l,r;
l = read();r = read();node[i] = (aa){l,r,i};
}
sort(node+1,node+1+m);
int l=1,r=0;
for(int i=1;i<=m;i++){
int ll = node[i].l,rr = node[i].r;
while(l>ll){
upd(--l);
}
while(r<rr){
upd(++r);
}
while(l<ll){
del(l++);
}
while(r>rr){
del(r--);
}
ans[node[i].id] = sum+(r-l+1-sum*2)/2*2+((r-l+1-sum*2)&1)*2;
}
for(int i=1;i<=m;i++){
cout<<ans[i]<<"\n";
}
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 20
Accepted
Test #1:
score: 20
Accepted
time: 0ms
memory: 1208kb
input:
8 8 167128212 174429419 167128212 621767731 167128212 818582273 113892562 167128212 2 7 1 7 2 7 6 7 ...
output:
5 7 5 2 3 4 4 5
result:
ok 8 numbers
Test #2:
score: 0
Accepted
time: 0ms
memory: 1212kb
input:
10 10 538223742 607314208 601616252 238348276 861683397 135271863 1049701173 601616252 601616252 207...
output:
5 4 7 7 6 4 2 3 5 2
result:
ok 10 numbers
Test #3:
score: 0
Accepted
time: 0ms
memory: 1212kb
input:
10 10 231956937 231956937 231956937 155054430 231956937 834151679 733426233 946937157 982922701 1061...
output:
5 3 8 7 6 3 2 3 2 7
result:
ok 10 numbers
Test #4:
score: 0
Accepted
time: 0ms
memory: 1216kb
input:
8 8 153266403 406479298 406479298 914995501 110116084 406479298 15057682 110116084 7 8 2 5 2 8 1 8 2...
output:
2 3 6 6 1 2 2 5
result:
ok 8 numbers
Test #5:
score: 0
Accepted
time: 0ms
memory: 1212kb
input:
8 8 526644202 174178431 1043048206 580637808 580637808 1043048206 18915475 1040962393 2 8 1 7 1 2 4 ...
output:
6 6 2 3 3 4 6 4
result:
ok 8 numbers
Subtask #2:
score: 30
Accepted
Test #6:
score: 30
Accepted
time: 3ms
memory: 1264kb
input:
1999 2000 394454733 851755323 386449476 718493013 955120853 104269318 1031993901 268524353 703718657...
output:
191 605 34 455 274 809 657 144 1075 603 112 460 468 468 437 400 467 437 813 58 535 730 226 105 208 3...
result:
ok 2000 numbers
Test #7:
score: 0
Accepted
time: 3ms
memory: 1264kb
input:
1993 2000 640807424 493229313 672197658 665973241 579425875 589166190 1037946442 345354963 125661187...
output:
172 673 264 521 883 852 649 406 689 622 301 165 1123 1077 317 715 770 1117 724 994 629 364 56 806 19...
result:
ok 2000 numbers
Test #8:
score: 0
Accepted
time: 0ms
memory: 1264kb
input:
1963 2000 456158469 1047546046 456158469 598666224 99387728 648437031 787319722 878036149 878036149 ...
output:
335 349 474 372 785 667 671 13 94 330 224 54 465 361 521 380 768 753 546 658 786 258 841 401 19 67 1...
result:
ok 2000 numbers
Test #9:
score: 0
Accepted
time: 0ms
memory: 1260kb
input:
1962 2000 810920845 490842776 262117172 880463066 880463066 1042602945 434666213 564732757 981334928...
output:
383 144 1122 899 630 1078 574 266 562 196 460 821 358 347 453 277 1001 201 5 752 21 258 172 311 241 ...
result:
ok 2000 numbers
Test #10:
score: 0
Accepted
time: 3ms
memory: 1260kb
input:
1961 2000 833394918 773046315 371306841 891295878 872234351 50300625 891295878 891295878 42666205 85...
output:
620 147 561 353 165 243 419 345 257 361 182 247 502 97 100 500 539 75 362 518 875 714 21 11 48 236 8...
result:
ok 2000 numbers
Subtask #3:
score: 50
Accepted
Test #11:
score: 50
Accepted
time: 958ms
memory: 6796kb
input:
196370 200000 176139558 339350106 805811735 492900090 716942482 390200365 924172453 991398756 864487...
output:
24755 69132 5047 108791 9885 54094 55458 74064 39621 87317 74212 10421 30142 41928 63117 44025 21937...
result:
ok 200000 numbers
Test #12:
score: 0
Accepted
time: 667ms
memory: 6808kb
input:
196811 200000 603813829 866654286 646010637 302979063 575451621 1030687033 1072702513 1072702513 897...
output:
80554 33771 74382 69863 6051 19919 23800 19807 77330 63026 34976 22186 16696 15923 3044 55472 72666 ...
result:
ok 200000 numbers
Test #13:
score: 0
Accepted
time: 633ms
memory: 6812kb
input:
197723 200000 215792904 222880022 269171699 161219085 42406545 944993597 1048184281 215792904 468912...
output:
43567 61672 93832 22258 12979 24930 1588 18488 18251 29615 21506 37030 107497 24959 33793 36160 5254...
result:
ok 200000 numbers
Test #14:
score: 0
Accepted
time: 608ms
memory: 6824kb
input:
199111 200000 763846066 875939375 290741854 408547569 544463804 25211399 751901581 788015486 3088405...
output:
34002 22162 2186 11443 9273 10745 7509 20583 42556 27678 61676 73934 44068 71991 11505 61004 45956 9...
result:
ok 200000 numbers
Test #15:
score: 0
Accepted
time: 615ms
memory: 6784kb
input:
196046 200000 999681108 214007186 405062282 1072683376 916307487 371991655 121702039 801844473 16891...
output:
53751 23924 15772 33744 39880 33140 106078 39843 77724 57428 40466 56082 54194 9512 33129 99722 1707...
result:
ok 200000 numbers