Task: | Vaihdot |
Sender: | ArktinenKarpalo |
Submission time: | 2020-09-06 17:55:00 +0300 |
Language: | C++ (C++11) |
Status: | READY |
Result: | 36 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 13 |
#2 | ACCEPTED | 23 |
#3 | WRONG ANSWER | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#2 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#3 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#4 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#5 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#6 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#7 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#8 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#9 | ACCEPTED | 0.01 s | 2, 3 | details |
#10 | ACCEPTED | 0.01 s | 2, 3 | details |
#11 | ACCEPTED | 0.01 s | 2, 3 | details |
#12 | ACCEPTED | 0.01 s | 2, 3 | details |
#13 | ACCEPTED | 0.02 s | 2, 3 | details |
#14 | ACCEPTED | 0.02 s | 2, 3 | details |
#15 | ACCEPTED | 0.01 s | 2, 3 | details |
#16 | ACCEPTED | 0.02 s | 2, 3 | details |
#17 | ACCEPTED | 0.21 s | 3 | details |
#18 | WRONG ANSWER | 0.21 s | 3 | details |
#19 | ACCEPTED | 0.21 s | 3 | details |
#20 | ACCEPTED | 0.22 s | 3 | details |
#21 | ACCEPTED | 0.22 s | 3 | details |
#22 | ACCEPTED | 0.24 s | 3 | details |
#23 | ACCEPTED | 0.38 s | 3 | details |
#24 | ACCEPTED | 0.42 s | 3 | details |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:110:8: warning: unused variable 'chg' [-Wunused-variable] int chg = 1-base+1; ^~~ input/code.cpp:125:7: warning: unused variable 'lk' [-Wunused-variable] int lk = 0; ^~
Code
#include <bits/stdc++.h> #define ll long long #define ull unsigned long long #define ld long double using namespace std; int n, a[202020], ar[202020], bs[202020]; int sp[2<<19][3]; void add(int k, int x, int G) { k += 2<<18; while(k>=1) { sp[k][G] += x; k /= 2; } } int sum(int left, int right, int G) { int ret = 0; left += 2<<18; right += 2<<18; while(left<=right) { if(right%2==0) ret += sp[right--][G]; if(left%2==1) ret += sp[left++][G]; right /= 2; left /= 2; } return ret; } int xyy(int a1, int b1) { int ret = 0; if(b1 <= ar[a1-1]) { ret++; } if(b1 > ar[a1+1]) { ret++; } return ret; } int xy(int a1, int b1) { return bs[a1]+bs[b1]-(xyy(a1, ar[b1]) + xyy(b1, ar[a1])); } vector<pair<int,int>> wt[202020]; int ans[1337]; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); cin >> n; srand(time(NULL)); for(int i=1; i<=n; i++) { cin >> a[i]; ar[a[i]] = i; } int rounds = 1; int last = -1; ar[0] = 0; ar[n+1] = n+1; for(int i=1; i<=n; i++) { if(ar[i] < last) rounds++; last = ar[i]; int base = xyy(i, ar[i]); wt[0].push_back(make_pair(ar[i], 1-base+1)); wt[min(ar[i-1], ar[i+1])].push_back(make_pair(-ar[i], 1-base+1)); if(ar[i-1] < ar[i+1]) { // 0 wt[ar[i-1]].push_back(make_pair(ar[i], 0-base+1)); wt[ar[i+1]].push_back(make_pair(-ar[i], 0-base+1)); wt[ar[i+1]].push_back(make_pair(ar[i], 1-base+1)); // m } else { // 2 wt[ar[i+1]].push_back(make_pair(ar[i], 2-base+1)); wt[ar[i-1]].push_back(make_pair(-ar[i], 2-base+1)); wt[ar[i-1]].push_back(make_pair(ar[i], 1-base+1)); // m } } for(int i=0; i<=n; i++) { for(auto u:wt[i]) { if(u.first > 0) { add(u.first, 1, u.second); } else { // add(-u.first, -1, u.second); } } if(i == 0) continue; vector<int> lol; for(int j=0; j<3; j++) { if(sum(ar[a[i]], ar[a[i]], j)) { add(ar[a[i]], -1, j); lol.push_back(j); } } int base = xyy(a[i], i); // 0, 1, 2 ec ans[(1-base)+(0-1) + 10] += sum(1, min(ar[a[i]-1], ar[a[i]+1])-1, 0)+sum(max(ar[a[i]-1], ar[a[i]+1]), n, 0); ans[(1-base)+(1-1) + 10] += sum(1, min(ar[a[i]-1], ar[a[i]+1])-1, 1)+sum(max(ar[a[i]-1], ar[a[i]+1]), n, 1); ans[(1-base)+(2-1) + 10] += sum(1, min(ar[a[i]-1], ar[a[i]+1])-1, 2)+sum(max(ar[a[i]-1], ar[a[i]+1]), n, 2); if(ar[a[i]-1] < ar[a[i]+1]) { // 0 int chg = 1-base+1; ans[(0-base)+(0-1) +10] += sum(ar[a[i]-1], ar[a[i]+1]-1, 0); ans[(0-base)+(1-1) +10] += sum(ar[a[i]-1], ar[a[i]+1]-1, 1); ans[(0-base)+(2-1) +10] += sum(ar[a[i]-1], ar[a[i]+1]-1, 2); } else { // 2 ans[(2-base)+(0-1) +10] += sum(ar[a[i]-1], ar[a[i]+1]-1, 0); ans[(2-base)+(1-1) +10] += sum(ar[a[i]-1], ar[a[i]+1]-1, 1); ans[(2-base)+(2-1) +10] += sum(ar[a[i]-1], ar[a[i]+1]-1, 2); } for(auto u:lol) add(ar[a[i]], 1, u); } int best = 1e9; int ans2 = 0; for(int i=0; i<=100; i++) { int lk = 0; if(ans[i] > 1) { best = i; ans2 = ans[i]; break; } } // cout << rounds << " " << best << " " << ans2 << " " << ans2/2; cout << rounds+best-10 << " " << ans2/2; //cout << rounds+best << " " << ans2/2; }
Test details
Test 1
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
100 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
correct output |
---|
2 99 |
user output |
---|
2 99 |
Test 2
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
100 100 99 98 97 96 95 94 93 92 91... |
correct output |
---|
98 4851 |
user output |
---|
98 4851 |
Test 3
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
100 1 2 88 4 5 6 7 8 9 10 11 12 13... |
correct output |
---|
16 5 |
user output |
---|
16 5 |
Test 4
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
100 51 48 74 70 45 71 24 88 55 99 ... |
correct output |
---|
49 131 |
user output |
---|
49 131 |
Test 5
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
100 45 67 29 62 70 77 41 74 52 95 ... |
correct output |
---|
52 268 |
user output |
---|
52 268 |
Test 6
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
100 47 98 2 75 6 21 84 8 4 89 27 9... |
correct output |
---|
48 149 |
user output |
---|
48 149 |
Test 7
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
100 73 68 17 94 71 63 61 13 58 10 ... |
correct output |
---|
47 116 |
user output |
---|
47 116 |
Test 8
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
100 17 16 45 94 6 1 36 81 31 13 51... |
correct output |
---|
45 95 |
user output |
---|
45 95 |
Test 9
Group: 2, 3
Verdict: ACCEPTED
input |
---|
5000 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
correct output |
---|
2 4999 |
user output |
---|
2 4999 |
Test 10
Group: 2, 3
Verdict: ACCEPTED
input |
---|
5000 5000 4999 4998 4997 4996 4995 ... |
correct output |
---|
4998 12492501 |
user output |
---|
4998 12492501 |
Test 11
Group: 2, 3
Verdict: ACCEPTED
input |
---|
5000 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
correct output |
---|
19 10 |
user output |
---|
19 10 |
Test 12
Group: 2, 3
Verdict: ACCEPTED
input |
---|
5000 1 2 3 4 5 6 264 8 9 10 11 12 1... |
correct output |
---|
190 96 |
user output |
---|
190 96 |
Test 13
Group: 2, 3
Verdict: ACCEPTED
input |
---|
5000 1 2 3 4 5 6 7 8 9 2400 11 12 1... |
correct output |
---|
1378 27938 |
user output |
---|
1378 27938 |
Test 14
Group: 2, 3
Verdict: ACCEPTED
input |
---|
5000 4012 2 4820 4208 1868 1728 362... |
correct output |
---|
2511 436307 |
user output |
---|
2511 436307 |
Test 15
Group: 2, 3
Verdict: ACCEPTED
input |
---|
5000 3877 3972 1112 3669 1959 4640 ... |
correct output |
---|
2497 417065 |
user output |
---|
2497 417065 |
Test 16
Group: 2, 3
Verdict: ACCEPTED
input |
---|
5000 2774 998 4525 2884 487 1995 41... |
correct output |
---|
2518 426448 |
user output |
---|
2518 426448 |
Test 17
Group: 3
Verdict: ACCEPTED
input |
---|
200000 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
correct output |
---|
2 199999 |
user output |
---|
2 199999 |
Test 18
Group: 3
Verdict: WRONG ANSWER
input |
---|
200000 200000 199999 199998 199997 19... |
correct output |
---|
199998 19999700001 |
user output |
---|
199998 672347169 |
Test 19
Group: 3
Verdict: ACCEPTED
input |
---|
200000 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
correct output |
---|
19 10 |
user output |
---|
19 10 |
Test 20
Group: 3
Verdict: ACCEPTED
input |
---|
200000 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
correct output |
---|
199 100 |
user output |
---|
199 100 |
Test 21
Group: 3
Verdict: ACCEPTED
input |
---|
200000 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
correct output |
---|
1979 1030 |
user output |
---|
1979 1030 |
Test 22
Group: 3
Verdict: ACCEPTED
input |
---|
200000 1 2 184153 4 5 6 7 8 164545 10... |
correct output |
---|
18081 477187 |
user output |
---|
18081 477187 |
Test 23
Group: 3
Verdict: ACCEPTED
input |
---|
200000 151013 68675 119105 58292 3335... |
correct output |
---|
86328 318722426 |
user output |
---|
86328 318722426 |
Test 24
Group: 3
Verdict: ACCEPTED
input |
---|
200000 11562 33356 106752 170825 2723... |
correct output |
---|
99873 663048119 |
user output |
---|
99873 663048119 |