QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#620293 | #5278. Mex and Cards | hbhz_zcy | WA | 180ms | 119136kb | C++14 | 2.0kb | 2024-10-07 17:23:33 | 2024-10-07 17:24:01 |
Judging History
answer
//g++ m.cpp -o m -g -std=c++14 -O0 -Wall
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<vector>
#define LL long long
using namespace std;
int qd(){
int rt=0;char c=getchar();
while(c<'0'||c>'9') c=getchar();
while('0'<=c&&c<='9') rt=(rt<<3)+(rt<<1)+c-48,c=getchar();
return rt;
}
const int maxn=2e6+10,_maxn=2e6;
struct node{int t,v;};
bool operator<(const node &x,const node &y){return x.t<y.t;}
set<node>f;
set<int>tn[maxn];
int N,a[maxn];LL ans=0;//7 5 3 -> 7 6 (5) 3 no 7 (5) 4 3
node backf(){auto it=f.end();if(it!=f.begin()) return *--it;else return {1,1};}
void calc(int t){
auto it=f.lower_bound({t,0});
if(it->t!=t){
it=f.insert(it,(node){t,a[t]});
auto l=it,r=it;l--,r++;
ans+=1LL*(r->t-it->t)*(it->v-l->v);
}
else{
auto r=it;r++;
ans+=1LL*(r->t-it->t)*(a[t]-it->v);
f.erase(it);
it=f.insert({t,a[t]}).first;
}
auto l=it,r=it;l--,r++;
if(l->v<=it->v){
ans-=1LL*(r->t-it->t)*(it->v-l->v);
f.erase(it);
}
else if(r->t!=N+1&&it->v<=r->v){
l=r=it=r;l--,r++;
ans-=1LL*(r->t-it->t)*(it->v-l->v);
f.erase(it);
}
}
int main(){
//freopen("a.in","r",stdin);
//freopen("a.out","w",stdout);
N=qd();
for(int i=1;i<=N;i++) a[i]=qd();
f.insert({0,_maxn});ans=-_maxn;
for(int i=1;i<=N+1;i++){
if(a[i]<backf().v) ans+=1LL*backf().v*(i-backf().t),f.insert({i,a[i]});
if(a[i]) tn[a[i]].insert(i);
}
if(backf().t!=N+1) f.insert({N+1,0});
printf("%lld\n",ans);
int Q=qd();
while(Q--){
int t=qd(),v=qd()+1,_av=a[v];a[v]+=t==1?1:-1;
if(_av) tn[_av].erase(tn[_av].find(v));
if(a[v]) tn[a[v]].insert(tn[a[v]].upper_bound(v),v);
calc(v);
auto it=tn[_av].upper_bound(v);
if(it!=tn[_av].end()) calc(*it);
printf("%lld\n",ans);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 13ms
memory: 98960kb
input:
5 2 1 3 0 2 6 1 0 1 1 2 4 1 3 2 1 2 1
output:
4 5 7 7 9 7 3
result:
ok 7 numbers
Test #2:
score: 0
Accepted
time: 3ms
memory: 98528kb
input:
1 0 0
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 10ms
memory: 99328kb
input:
10 3 8 1 4 10 3 10 9 7 10 20 2 5 1 4 1 2 1 4 1 3 1 3 1 0 2 8 1 5 1 4 1 0 1 3 1 8 1 6 1 4 1 1 1 5 1 9 1 6 2 7
output:
14 14 14 22 22 22 22 24 24 24 24 26 26 26 26 26 26 26 26 26 26
result:
ok 21 numbers
Test #4:
score: 0
Accepted
time: 10ms
memory: 98660kb
input:
10 9 8 7 5 5 4 3 2 1 1 20 2 4 1 8 2 6 1 2 1 2 2 5 2 2 1 0 1 6 1 6 2 9 1 2 2 7 2 8 2 3 1 9 1 7 1 4 2 6 1 7
output:
45 44 45 44 45 45 44 44 45 46 46 45 45 43 43 42 43 44 44 44 45
result:
ok 21 numbers
Test #5:
score: 0
Accepted
time: 8ms
memory: 98976kb
input:
100 969 519 608 546 957 82 670 100 92 581 974 529 970 54 639 216 238 620 966 162 430 10 446 884 895 292 450 180 619 389 943 855 204 605 514 997 325 98 643 915 744 249 333 431 160 434 714 976 168 573 682 69 873 285 668 561 159 858 864 683 266 564 350 214 461 421 213 568 279 624 749 433 735 437 978 95...
output:
4923 4923 4923 4923 4923 4923 4923 4923 4923 4927 4927 4927 4927 4927 4927 4927 4927 4927 4927 4927 4927 4927 4927 4927 4927 4927 4927 4927 4927 4927 4927 4927 4927 4927 4927 4927 4931 4931 4931 4931 4931 4931 4931 4931 4931 4931 4931 4931 4931 4931 4931 4931 4931 4931 4931 4931 4931 4931 4931 4931 ...
result:
ok 1001 numbers
Test #6:
score: 0
Accepted
time: 7ms
memory: 99324kb
input:
100 994 983 981 980 962 959 959 950 933 887 877 869 841 828 809 807 803 793 789 778 773 772 768 767 765 765 759 757 749 747 742 738 730 724 681 675 656 638 627 626 615 612 593 592 545 543 540 534 531 529 525 520 518 515 512 510 500 494 472 472 432 415 414 411 399 375 350 328 315 307 292 261 258 246 ...
output:
51041 51042 51041 51042 51043 51042 51043 51042 51040 51038 51037 51038 51039 51038 51039 51040 51039 51040 51039 51038 51037 51036 51037 51038 51037 51038 51037 51036 51035 51036 51037 51035 51034 51035 51034 51035 51036 51037 51036 51037 51039 51038 51037 51036 51035 51034 51033 51032 51031 51032 ...
result:
ok 1001 numbers
Test #7:
score: 0
Accepted
time: 4ms
memory: 97852kb
input:
1000 549187 776775 748956 28001 575132 18015 112492 144497 206885 842190 403842 456113 424268 871411 648618 186832 693358 781526 443190 175126 586343 918652 923262 973941 509929 433837 392849 452585 497398 331180 118333 152788 959909 539943 747365 261855 819641 618091 801231 355664 285761 895793 398...
output:
6317898 6317898 6317898 6317898 6317898 6317898 6317898 6317898 6317898 6317898 6317898 6317898 6317898 6317898 6317898 6317898 6317898 6317898 6317898 6317898 6317898 6317898 6317898 6317898 6317898 6317898 6317898 6317898 6317898 6317898 6317898 6317898 6317898 6317898 6317898 6317898 6317898 6317...
result:
ok 10001 numbers
Test #8:
score: 0
Accepted
time: 12ms
memory: 99648kb
input:
1000 999823 997756 997661 997567 995015 993681 993623 993621 993428 993163 990908 989370 987917 986483 984926 983477 982705 982330 982173 981725 981590 980871 980406 978064 976231 974657 969279 968447 968067 967307 966294 965934 965581 964707 964400 962842 962262 961936 961798 961105 958480 957851 9...
output:
515262961 515262960 515262959 515262958 515262959 515262960 515262961 515262960 515262961 515262962 515262963 515262964 515262963 515262964 515262963 515262964 515262965 515262964 515262965 515262966 515262965 515262966 515262967 515262966 515262967 515262968 515262969 515262968 515262967 515262966 ...
result:
ok 10001 numbers
Test #9:
score: 0
Accepted
time: 45ms
memory: 98940kb
input:
10000 810601 729711 139357 433916 959178 573779 86115 773421 634334 59653 613563 529054 644885 727194 44262 709529 1681 469658 158976 628846 642964 486044 969568 598670 753102 925097 495487 506784 238141 791563 750457 218880 115527 944709 664199 321209 984344 317419 568689 296228 50862 458459 766006...
output:
6625728 6625728 6625728 6625728 6625728 6625728 6625728 6625728 6625728 6625728 6625728 6625728 6625728 6625728 6625728 6625728 6625728 6625728 6625728 6625728 6625728 6625728 6625728 6625728 6625728 6625728 6625728 6625728 6625728 6625728 6625728 6625728 6625728 6625728 6625728 6625728 6625728 6625...
result:
ok 200001 numbers
Test #10:
score: 0
Accepted
time: 71ms
memory: 98504kb
input:
10000 999881 999862 999854 999798 999750 999710 999412 999389 999270 998698 998592 998557 998315 998147 998082 998080 998006 997734 997662 997601 997508 997439 997415 997336 997118 997049 997037 996886 996794 996734 996724 996654 996654 996423 996381 996276 996179 995968 995639 995300 995289 995246 ...
output:
5011255149 5011255148 5011255147 5011255148 5011255149 5011255148 5011255147 5011255148 5011255149 5011255148 5011255147 5011255148 5011255149 5011255148 5011255149 5011255148 5011255147 5011255148 5011255149 5011255147 5011255146 5011255145 5011255146 5011255147 5011255146 5011255145 5011255144 501...
result:
ok 200001 numbers
Test #11:
score: 0
Accepted
time: 81ms
memory: 110688kb
input:
200000 954932 478728 762927 818548 978278 196477 518754 158676 100286 637040 576732 579262 510238 196651 497902 72985 69112 722929 769712 408173 559817 756434 192540 297097 772778 765866 552840 963172 596523 91866 316071 470277 918307 252349 439797 195172 659054 903280 874588 197108 881845 654102 49...
output:
8828666 8828666 8828666 8828666 8828666 8828666 8828666 8828666 8828666 8828666 8828666 8828666 8828666 8828666 8828666 8828666 8828666 8828666 8828666 8828666 8828666 8828666 8828666 8828666 8828666 8828666 8828666 8828666 8828666 8828666 8828666 8828666 8828666 8828666 8828666 8828666 8828666 8828...
result:
ok 200001 numbers
Test #12:
score: 0
Accepted
time: 176ms
memory: 116692kb
input:
200000 1000000 1000000 999994 999993 999992 999991 999978 999975 999973 999972 999959 999956 999955 999940 999937 999928 999928 999925 999923 999917 999916 999906 999904 999903 999894 999889 999888 999885 999883 999876 999875 999873 999871 999868 999862 999854 999850 999841 999831 999826 999815 9998...
output:
99850068284 99850068283 99850068284 99850068283 99850068282 99850068283 99850068284 99850068283 99850068284 99850068283 99850068282 99850068283 99850068284 99850068283 99850068282 99850068283 99850068284 99850068282 99850068280 99850068279 99850068278 99850068279 99850068278 99850068278 99850068279 ...
result:
ok 200001 numbers
Test #13:
score: 0
Accepted
time: 98ms
memory: 109748kb
input:
200000 554429 815547 991851 877055 4532 462959 254230 849016 817417 522300 178108 87935 418464 198583 568638 156649 672927 961839 278499 102007 523645 288807 991952 147030 477770 977147 163962 984865 173912 276913 85410 762670 580034 737244 549479 937246 188784 443181 132471 156270 651436 9418 61925...
output:
10904793 10904793 10904793 10904793 10904793 10904793 10904793 10904793 10904793 10904793 10904793 10904793 10904793 10904793 10904793 10904793 10904793 10904793 10904793 10904793 10904793 10904793 10904793 10904793 10904793 10904793 10904793 10904793 10904793 10904793 10904793 10904793 10904793 109...
result:
ok 200001 numbers
Test #14:
score: 0
Accepted
time: 180ms
memory: 116396kb
input:
200000 999996 999993 999992 999988 999987 999983 999983 999981 999977 999974 999966 999956 999949 999938 999929 999926 999926 999922 999914 999911 999901 999898 999898 999895 999894 999884 999882 999875 999872 999869 999860 999848 999835 999826 999814 999797 999788 999786 999781 999778 999768 999762...
output:
100097520798 100097520796 100097520795 100097520794 100097520793 100097520792 100097520791 100097520789 100097520788 100097520787 100097520786 100097520785 100097520784 100097520783 100097520782 100097520781 100097520780 100097520778 100097520777 100097520776 100097520775 100097520774 100097520773 1...
result:
ok 200001 numbers
Test #15:
score: 0
Accepted
time: 82ms
memory: 110684kb
input:
200000 395501 808050 24796 308616 250220 843848 709987 740492 754049 691635 159592 436497 742581 537843 994911 496052 511054 801461 866977 318572 301284 90981 721091 977254 108792 33583 320255 939412 163087 981014 87104 880366 441858 16628 791941 430163 740742 730081 710770 829061 648984 488080 2953...
output:
14172681 14172681 14172681 14172681 14172681 14172681 14172681 14172681 14172681 14172681 14172681 14172681 14172681 14172681 14172681 14172681 14172681 14172681 14172681 14172681 14172681 14172681 14172681 14172681 14172681 14172681 14172681 14172681 14172681 14172681 14172681 14172681 14172681 141...
result:
ok 200001 numbers
Test #16:
score: 0
Accepted
time: 170ms
memory: 119136kb
input:
200000 999996 999992 999984 999983 999972 999961 999955 999953 999948 999946 999945 999938 999936 999933 999919 999914 999907 999905 999900 999900 999899 999896 999894 999891 999889 999887 999885 999869 999849 999848 999847 999845 999844 999841 999836 999833 999829 999826 999823 999821 999819 999810...
output:
99858339546 99858339546 99858339547 99858339548 99858339549 99858339549 99858339550 99858339551 99858339552 99858339552 99858339553 99858339554 99858339555 99858339556 99858339557 99858339558 99858339559 99858339559 99858339560 99858339561 99858339562 99858339563 99858339564 99858339565 99858339566 ...
result:
ok 200001 numbers
Test #17:
score: -100
Wrong Answer
time: 34ms
memory: 100188kb
input:
200000 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...
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:
wrong answer 116614th numbers differ - expected: '1', found: '200000'