Task: | Pizzeriat |
Sender: | Olli |
Submission time: | 2018-01-14 19:46:42 +0200 |
Language: | C++ |
Status: | READY |
Result: | 43 |
group | verdict | score |
---|---|---|
#1 | WRONG ANSWER | 0 |
#2 | ACCEPTED | 43 |
#3 | WRONG ANSWER | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | WRONG ANSWER | 0.06 s | 1 | details |
#2 | WRONG ANSWER | 0.04 s | 1 | details |
#3 | WRONG ANSWER | 0.05 s | 1 | details |
#4 | ACCEPTED | 0.74 s | 2 | details |
#5 | ACCEPTED | 0.77 s | 2 | details |
#6 | ACCEPTED | 0.75 s | 2 | details |
#7 | WRONG ANSWER | 0.46 s | 3 | details |
#8 | WRONG ANSWER | 0.45 s | 3 | details |
#9 | WRONG ANSWER | 0.46 s | 3 | details |
Code
#include <iostream> using namespace std; const int N = 1e5 + 5; const int M = 131072; int table[N]; int beginning[N]; int ending[N]; int treeB[2*M]; int treeE[2*M]; int n, q; void prep() { for(int i = M; i < M + n; ++i) { treeB[i] = beginning[i - M + 1]; treeE[i] = ending[i - M + 1]; } for(int i = M + n; i < 2*M; ++i) { treeB[i] = 1e9; treeE[i] = 1e9; } for(int i = M - 1; i >= 1; --i) { treeB[i] = min(treeB[2*i], treeB[2*i + 1]); treeE[i] = min(treeE[2*i], treeE[2*i + 1]); } } void update(int i, int x) { i += M - 1; treeB[i] = x; treeE[i] = x; i/=2; while(i > 0) { treeB[i] = min(treeB[2*i], treeB[2*i + 1]); treeE[i] = min(treeE[2*i], treeE[2*i + 1]); i/=2; } } pair<int, int> find(int a, int b) { a+= M-1; b+= M-1; int ansB = 1e9; int ansE = 1e9; while(a <= b) { if(a%2 == 1) { ansB = min(ansB, treeB[a]); ansE = min(ansE, treeE[a]); ++a; } if(b%2 == 0) { ansB = min(ansB, treeB[b]); ansE = min(ansE, treeE[b]); --b; } a/=2; b/=2; } return make_pair(ansB, ansE); //return ansB; } int findIndexbeginning(int a, int b) { if(a == b) { return a; } int middle = (a+b)/2; if(find(a, middle).first == find(a, b).first) { return findIndexbeginning(a, middle); } return findIndexbeginning(middle + 1, b); } int findIndexending(int a, int b) { if(a == b) { return a; } int middle = (a+b)/2; if(find(a, middle).second == find(a, b).second) { return findIndexending(a, middle); } return findIndexending(middle + 1, b); } int main() { cin >> n >> q; for(int i = 1; i <= n; ++i) { int a; cin >> a; table[i] = a; beginning[i] = a + n - i; ending[i] = a + i - 1; } prep(); for(int i = 0; i < q; ++i) { int type; cin >> type; /*for(int j = 1; j <= n; ++j) { cout << table[j] << " "; } cout << "\n"; for(int j = 1; j <= n; ++j) { cout << beginning[j] << " "; } cout << "\n"; for(int j = 1; j <= n; ++j) { cout << ending[j] << " "; } cout << "\n"; */ if(type == 2) { int spot; cin >> spot; int ans = findIndexbeginning(1, spot); int second = findIndexending(spot, n); //cout << ans << " " << second << " "; cout << min(table[ans] + spot - ans, table[second] + second - spot) << "\n"; } else { int k, x; cin >> k >> x; table[k] = x; update(k, x); } } }
Test details
Test 1
Group: 1
Verdict: WRONG ANSWER
input |
---|
1000 1000 720 271 760 576 363 23 368 995... |
correct output |
---|
43 12 40 22 18 ... |
user output |
---|
43 12 40 22 78 ... |
Test 2
Group: 1
Verdict: WRONG ANSWER
input |
---|
1000 1000 720 18 984 261 344 257 686 441... |
correct output |
---|
10 20 27 37 73 ... |
user output |
---|
10 20 27 37 73 ... |
Test 3
Group: 1
Verdict: WRONG ANSWER
input |
---|
1000 1000 120 764 890 848 949 59 894 916... |
correct output |
---|
24 25 13 16 19 ... |
user output |
---|
24 25 13 16 19 ... |
Test 4
Group: 2
Verdict: ACCEPTED
input |
---|
100000 100000 11763 43585 3126 3787 79765 64... |
correct output |
---|
284 143 346 203 157 ... |
user output |
---|
284 143 346 203 157 ... |
Test 5
Group: 2
Verdict: ACCEPTED
input |
---|
100000 100000 76947 78386 71190 65478 90345 ... |
correct output |
---|
459 297 128 234 204 ... |
user output |
---|
459 297 128 234 204 ... |
Test 6
Group: 2
Verdict: ACCEPTED
input |
---|
100000 100000 39277 33504 98385 58115 28655 ... |
correct output |
---|
234 221 156 455 78 ... |
user output |
---|
234 221 156 455 78 ... |
Test 7
Group: 3
Verdict: WRONG ANSWER
input |
---|
100000 100000 46508 6952 22836 54480 91235 2... |
correct output |
---|
427 409 352 39 388 ... |
user output |
---|
427 515 352 396 561 ... |
Test 8
Group: 3
Verdict: WRONG ANSWER
input |
---|
100000 100000 15918 8771 36223 76330 39229 7... |
correct output |
---|
316 387 435 330 446 ... |
user output |
---|
316 387 762 874 40545 ... |
Test 9
Group: 3
Verdict: WRONG ANSWER
input |
---|
100000 100000 87734 39225 78667 43704 17207 ... |
correct output |
---|
228 83 176 428 273 ... |
user output |
---|
379 567 29489 15190 42211 ... |