QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#616768 | #8634. 求和 | xng | 0 | 138ms | 27136kb | C++14 | 1.3kb | 2024-10-06 11:18:14 | 2024-10-06 11:18:15 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
using namespace std;
//const int N = 2e5 + 30;
//#pragma GCC optimize(3)
//#pragma GCC optimize(2)
ll n,a[1000006],h[1000006],cnt[1000006],l=2000006,r=-1,bo,ans,k,kl,kml,kmr,kr,ans2;
//bool bo[1000006];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
// freopen("mex.in","r",stdin);
// freopen("mex.out","w",stdout);
cin>>n;
// cin>>n;
for(ll i=1;i<=n;i++){
cin>>a[i];
// cin>>a[i];
h[a[i]]=i;
}
for(ll i=0;i<=n;i++){
bo=0;
kml=l;
kmr=r;
if(i!=n&&l>h[i]){
l=h[i];
bo=-1;
}
if(i!=n&&r<h[i]){
r=h[i];
bo=1;
}
if(i==0){
// cnt[i]=(h[i]*(h[i]-1)/2)+((n-h[i])*(n-h[i]+1)/2);
continue;
}
if(i==n){
cnt[i]=l+(n-r);
continue;
}
if(bo==0){
cnt[i]=0;
continue;
}
if(bo==-1){
kl=l;
kr=n;
}
if(bo==1){
kl=1;
kr=r;
}
// cout<<k<<endl;
cnt[i]=kml-kl+kr-kmr;
}
for(ll i=1;i<=n;i++){
// cout<<cnt[i]<<" ";
ans+=cnt[i]*i;
}
// cout<<endl;
// ans/=2;
// cout<<ans;
// for(int i=1;i<=n;i++){
// for(int j=i;j<=n;j++){
// for(int k=i;k<=j;k++){
// bo[k]
// }
// }
// }
cout<<ans;
return 0;
}
详细
Pretests
Final Tests
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 7720kb
input:
7 6 2 5 1 3 0 4
output:
30
result:
wrong answer 1st numbers differ - expected: '33', found: '30'
Test #2:
score: 0
Wrong Answer
time: 0ms
memory: 7800kb
input:
9 4 3 7 8 0 5 2 1 6
output:
42
result:
wrong answer 1st numbers differ - expected: '56', found: '42'
Test #3:
score: 0
Wrong Answer
time: 1ms
memory: 7648kb
input:
298 297 296 295 294 275 292 291 142 289 288 287 286 285 284 283 282 161 280 279 278 277 276 293 274 273 272 271 270 269 268 267 266 104 264 263 262 261 260 259 198 257 256 255 254 253 252 251 250 249 123 247 246 41 244 53 240 236 235 230 226 223 221 127 219 212 27 210 209 208 207 90 205 204 201 200 ...
output:
237369
result:
wrong answer 1st numbers differ - expected: '1056340', found: '237369'
Test #4:
score: 0
Wrong Answer
time: 0ms
memory: 7800kb
input:
300 268 239 152 49 26 206 293 79 24 203 55 96 246 22 274 187 272 130 273 9 298 236 256 44 144 163 123 111 89 108 101 295 143 242 33 63 16 105 14 129 39 112 58 47 65 291 69 146 23 70 264 192 172 215 20 198 226 100 127 15 72 114 282 225 195 6 48 289 74 262 219 59 251 217 209 126 52 117 91 235 199 177 ...
output:
9066
result:
wrong answer 1st numbers differ - expected: '67785', found: '9066'
Test #5:
score: 0
Wrong Answer
time: 1ms
memory: 7716kb
input:
297 280 276 272 224 270 266 265 262 261 259 258 257 256 255 254 253 252 248 245 244 215 242 240 239 238 237 235 225 223 222 221 220 217 287 243 210 208 206 205 203 107 191 23 187 186 185 184 182 180 179 178 177 176 175 174 172 170 165 163 161 159 157 153 152 151 150 149 147 145 142 141 139 137 133 1...
output:
57326
result:
wrong answer 1st numbers differ - expected: '590900', found: '57326'
Test #6:
score: 0
Wrong Answer
time: 0ms
memory: 7736kb
input:
300 268 239 152 49 26 206 293 79 24 203 55 96 246 22 274 187 272 130 273 9 298 236 256 44 144 163 123 111 89 108 101 295 143 242 33 63 16 105 14 129 39 112 58 47 65 291 69 146 23 70 264 192 172 215 20 198 226 100 127 15 72 114 282 225 195 6 48 289 74 262 219 59 251 217 209 126 52 117 91 235 199 177 ...
output:
9066
result:
wrong answer 1st numbers differ - expected: '67785', found: '9066'
Test #7:
score: 0
Wrong Answer
time: 0ms
memory: 7740kb
input:
4999 4910 4909 4905 4904 4900 4898 4897 4896 4894 4891 4888 4886 4884 4883 4881 4879 4878 4876 4875 747 4872 4870 4868 4867 4865 4864 4862 4858 4857 4856 4855 4852 4851 4846 4843 4842 4841 4840 4838 4836 4834 4833 4831 4830 4829 4828 4827 4826 4825 2517 4821 4820 4818 4817 4816 4815 4814 4813 4810 4...
output:
3201645
result:
wrong answer 1st numbers differ - expected: '89784206', found: '3201645'
Test #8:
score: 0
Wrong Answer
time: 2ms
memory: 7840kb
input:
4998 1832 4930 2892 4114 3548 4372 980 4101 2775 2241 779 3438 932 2782 3170 3237 4370 3162 1435 2997 4965 4043 791 1557 795 2616 390 3927 2310 1846 1516 535 4933 1071 2370 4594 128 4201 666 1800 4362 3889 1203 2506 1155 1722 2703 1726 810 794 4301 2832 3655 1059 1729 4829 4948 1662 4341 243 3244 67...
output:
168407
result:
wrong answer 1st numbers differ - expected: '14050945', found: '168407'
Test #9:
score: 0
Wrong Answer
time: 0ms
memory: 7748kb
input:
4996 4884 4883 4880 4877 4876 4873 4872 4871 4870 4868 4867 1554 4864 4859 4858 4857 4856 4849 4848 4846 4843 4841 4840 4838 4837 4836 4833 4829 4827 4826 4825 4819 4817 4813 4812 4810 4807 4802 4801 4799 4798 4797 4796 4795 4793 4792 4791 4789 4788 4787 4786 4784 4781 4780 4774 4773 4772 4770 4769 ...
output:
4238041
result:
wrong answer 1st numbers differ - expected: '205335278', found: '4238041'
Test #10:
score: 0
Wrong Answer
time: 2ms
memory: 7664kb
input:
4999 1832 4930 2892 4114 3548 4372 980 4101 2775 2241 779 3438 932 2782 3170 3237 4370 3162 1435 2997 4965 4043 791 1557 795 2616 390 3927 2310 1846 1516 535 4933 1071 2370 4594 128 4201 666 1800 4362 3889 1203 2506 1155 1722 2703 1726 810 794 4301 2832 3655 1059 1729 4829 4948 1662 4341 243 3244 67...
output:
141172
result:
wrong answer 1st numbers differ - expected: '13952453', found: '141172'
Test #11:
score: 0
Wrong Answer
time: 43ms
memory: 27056kb
input:
999998 999142 999138 999135 999133 999132 999131 999128 999127 999125 999123 999122 999121 999116 999111 999108 999105 999103 999102 999101 999099 999096 999092 999090 999089 999088 999085 999084 999083 999082 999080 999078 999076 999075 999073 999072 999070 999068 999067 999065 999064 999063 999062...
output:
207729986074
result:
wrong answer 1st numbers differ - expected: '453346820756985', found: '207729986074'
Test #12:
score: 0
Wrong Answer
time: 131ms
memory: 27060kb
input:
999998 573780 608453 374999 149892 905671 391303 515911 787220 13024 597466 183671 267692 602322 203119 698431 948967 428018 269311 151297 8213 371857 258337 748054 63185 569822 516690 158317 460968 764763 561512 820476 308120 665989 299288 461448 378882 816621 897864 909236 61226 825295 450849 5588...
output:
68023716
result:
wrong answer 1st numbers differ - expected: '640456985452', found: '68023716'
Test #13:
score: 0
Wrong Answer
time: 51ms
memory: 26988kb
input:
1000000 999999 999998 999997 999996 999995 999994 999993 999992 999991 999990 999989 999988 999987 999986 999985 999984 999983 999982 999981 999980 999979 999978 999977 999976 999975 999974 999973 999972 999971 999970 999969 999968 999967 999966 999965 999964 999963 999962 999961 999960 999959 99995...
output:
216490159542
result:
wrong answer 1st numbers differ - expected: '122904492236287', found: '216490159542'
Test #14:
score: 0
Wrong Answer
time: 129ms
memory: 27040kb
input:
999996 102854 632174 545589 425037 604248 560072 705933 386322 916304 161176 466245 562424 198930 652815 297443 165498 538145 802714 430847 417296 645926 474721 469090 480945 518185 262211 455185 389167 712274 882882 217005 925059 657786 869334 881654 561255 697120 678309 900212 410660 319454 802285...
output:
44724794
result:
wrong answer 1st numbers differ - expected: '420320000574', found: '44724794'
Test #15:
score: 0
Wrong Answer
time: 47ms
memory: 27008kb
input:
999997 999493 999491 999489 999488 999487 999486 999485 999482 999479 999476 999474 999473 999472 999471 999470 999469 999466 999465 999464 999462 999460 999459 999456 999455 999449 999448 999447 999446 999444 999440 999439 999438 999437 999435 999433 999432 999429 999427 999426 999424 999417 999415...
output:
483842897667
result:
wrong answer 1st numbers differ - expected: '213505515788254', found: '483842897667'
Test #16:
score: 0
Wrong Answer
time: 129ms
memory: 27048kb
input:
999999 573780 608453 374999 149892 905671 391303 515911 787220 13024 597466 183671 267692 602322 203119 698431 948967 428018 269311 151297 8213 371857 258337 748054 63185 569822 516690 158317 460968 764763 561512 820476 308120 665989 299288 461448 378882 816621 897864 909236 61226 825295 450849 5588...
output:
70059406
result:
wrong answer 1st numbers differ - expected: '640472696831', found: '70059406'
Test #17:
score: 0
Wrong Answer
time: 51ms
memory: 26980kb
input:
1000000 999999 999998 999997 999996 999995 999994 999993 999992 999991 999990 999989 999988 999987 999986 999985 999984 999983 999982 999981 999980 999979 999978 999977 999976 999975 999974 999973 999972 999971 999970 999969 999968 999967 999966 999965 999964 999963 999962 999961 999960 999959 99995...
output:
216490159542
result:
wrong answer 1st numbers differ - expected: '122904492236287', found: '216490159542'
Test #18:
score: 0
Wrong Answer
time: 135ms
memory: 27048kb
input:
999999 884235 988504 861523 555695 833984 876468 853973 875250 10915 493469 490446 628442 817438 96931 22527 271938 19684 907164 128033 74716 334003 479052 653289 189210 825545 837077 389951 25834 798677 207112 387262 239710 243701 412148 266157 849491 414525 186093 826214 49620 121852 468444 882681...
output:
35228635
result:
wrong answer 1st numbers differ - expected: '12948507818', found: '35228635'
Test #19:
score: 0
Wrong Answer
time: 47ms
memory: 26988kb
input:
999998 999142 999138 999135 999133 999132 999131 999128 999127 999125 999123 999122 999121 999116 999111 999108 999105 999103 999102 999101 999099 999096 999092 999090 999089 999088 999085 999084 999083 999082 999080 999078 999076 999075 999073 999072 999070 999068 999067 999065 999064 999063 999062...
output:
207729986074
result:
wrong answer 1st numbers differ - expected: '453346820756985', found: '207729986074'
Test #20:
score: 0
Wrong Answer
time: 138ms
memory: 27136kb
input:
999999 884235 988504 861523 555695 833984 876468 853973 875250 10915 493469 490446 628442 817438 96931 22527 271938 19684 907164 128033 74716 334003 479052 653289 189210 825545 837077 389951 25834 798677 207112 387262 239710 243701 412148 266157 849491 414525 186093 826214 49620 121852 468444 882681...
output:
35228635
result:
wrong answer 1st numbers differ - expected: '12948507818', found: '35228635'