QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#446242 | #8578. 과일 게임 | Wansur | 5 | 2102ms | 750520kb | C++23 | 5.1kb | 2024-06-17 02:52:46 | 2024-06-17 02:52:47 |
Judging History
answer
#include <bits/stdc++.h>
#define f first
#define s second
#define ent '\n'
using namespace std;
typedef long long ll;
int get(deque<pair<int, int>> dq){
int ans = 0;
for(int i=0;i+1<dq.size();i++){
if(dq[i].f > dq[i+1].f){
break;
}
dq[i+1].s += (dq[i].s >> (dq[i+1].f - dq[i].f));
}
for(int i=dq.size()-1;i>=1;i--){
if(dq[i].f > dq[i-1].f){
continue;
}
dq[i-1].s += (dq[i].s >> (dq[i-1].f - dq[i].f));
}
for(auto [x, y]:dq){
while(y > 1){
x++;
y /= 2;
}
ans = max(ans, x);
}
return ans;
}
struct asd{
deque<pair<int, int>> pref, suff;
bool same = 1;
int mx = 0;
asd(){
pref.clear(), suff.clear();
same = 1;
mx = 0;
}
asd(int x){
pref = suff = {{x, 1}};
same = 1;
mx = x;
}
void insert(pair<int, int> T){
auto [x, c] = T;
if(suff.size() && suff.back().f == x){
suff[suff.size()-1].s += c;
if(same){
pref[pref.size()-1].s += c;
}
return;
}
bool f = 0;
while(suff.size() > 1 && suff[suff.size()-2].f > suff.back().f && suff.back().f < x){
if(suff.back().s % 2 == 0){
f = 1;
auto [x, y] = suff.back();
suff.pop_back();
if(x+1 == suff.back().f){
suff.back().s += y/2;
}
else{
suff.push_back({x+1, y / 2});
}
if(same){
pref.pop_back();
if(x + 1 == pref.back().f){
pref.back().s += y/2;
}
else{
pref.push_back({x+1, y / 2});
}
}
continue;
}
if(same){
same = 0;
auto [x, y] = pref.back();
pref.pop_back();
if(pref.size() && pref.back().f == x+1){
pref.back().s += y / 2;
}
else{
if(y > 1) pref.push_back({x+1, y/2});
}
pref.push_back({x, 1});
mx = max(mx, get(pref));
}
while(suff.size() > 1){
suff.pop_front();
}
int v = x;
auto [x, y] = suff.back();
suff.pop_back();
suff.push_back({x, 1});
if(y > 1){
suff.push_back({x+1, y / 2});
}
if(suff.back().f == v){
suff.back().s += c;
}
else{
suff.push_back({v, c});
}
mx = max(mx, get(suff));
return;
}
if(suff.size() && suff.back().f == x){
suff[suff.size()-1].s += c;
if(same){
pref[pref.size()-1].s += c;
}
if(f){
mx = max({mx, get(suff), get(pref)});
}
return;
}
suff.push_back({x, c});
if(same){
pref.push_back({x, c});
}
if(f){
mx = max({mx, get(suff), get(pref)});
}
return;
}
asd operator +(asd x){
asd ans;
ans.suff = suff;
ans.same = same;
ans.pref = pref;
ans.mx = max(mx, x.mx);
for(auto y:x.pref){
ans.insert(y);
}
ans.mx = max(ans.mx, get(ans.suff));
if(!x.same) {
ans.same = 0;
ans.suff = x.suff;
}
ans.mx = max(ans.mx, get(ans.pref));
ans.mx = max(ans.mx, get(ans.suff));
return ans;
}
} t[400002];
int a[100020];
int n, m, k;
void build(int v,int tl,int tr){
if(tl == tr){
t[v] = asd(a[tl]);
}
else{
int mid = tl + tr >> 1;
build(v*2, tl, mid);
build(v*2+1, mid+1, tr);
t[v] = t[v*2] + t[v*2+1];
}
}
void upd(int v, int tl, int tr, int pos, int x){
if(tl == tr){
t[v] = asd(x);
}
else{
int mid = tl + tr >> 1;
if(pos <= mid){
upd(v*2, tl, mid, pos, x);
}
else{
upd(v*2+1, mid+1, tr, pos, x);
}
t[v] = t[v*2] + t[v*2+1];
}
}
asd get(int v, int tl, int tr, int l, int r){
if(tl > r || l > tr){
return t[0];
}
if(tl >= l && tr <= r){
return t[v];
}
int mid = tl + tr >> 1;
return get(v*2, tl, mid, l, r) + get(v*2+1, mid+1, tr, l, r);
}
void prepare_game(vector<int> A) {
n = A.size();
for(int i=0;i<n;i++){
a[i+1] = A[i];
}
build(1, 1, n);
}
int play_game(int l, int r) {
l++, r++;
return get(1, 1, n, l, r).mx;
}
void update_game(int p, int v) {
p++;
upd(1, 1, n, p, v);
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 84ms
memory: 544832kb
input:
10 2 2 1 2 2 2 2 1 2 2 10 1 0 2 1 0 9 1 0 5 1 2 4 1 0 9 1 2 7 1 3 7 1 7 9 1 1 3 1 0 2
output:
3 4 3 3 4 4 4 3 2 3
result:
ok 10 lines
Test #2:
score: 0
Accepted
time: 80ms
memory: 544780kb
input:
10 1 1 2 1 2 2 1 2 1 1 10 1 3 4 1 2 6 1 0 2 1 0 2 1 4 5 1 3 9 1 0 6 1 5 8 1 4 9 1 2 7
output:
2 3 3 3 3 3 3 2 3 3
result:
ok 10 lines
Test #3:
score: 0
Accepted
time: 92ms
memory: 544780kb
input:
10 1 2 1 2 2 2 2 1 2 2 10 1 0 2 1 1 2 1 0 1 1 1 1 1 8 9 1 3 5 1 4 7 1 1 9 1 3 6 1 6 7
output:
2 2 2 2 3 3 3 4 4 2
result:
ok 10 lines
Test #4:
score: 0
Accepted
time: 64ms
memory: 544776kb
input:
10 2 1 2 1 1 1 1 2 1 2 10 1 4 5 1 0 6 1 7 8 1 4 5 1 0 7 1 4 7 1 4 9 1 3 7 1 0 9 1 2 9
output:
2 3 2 2 4 3 3 3 4 4
result:
ok 10 lines
Test #5:
score: 0
Accepted
time: 80ms
memory: 544488kb
input:
10 1 1 1 1 1 1 1 1 1 1 10 2 2 1 2 7 1 2 5 1 2 6 1 2 8 1 1 4 6 2 6 1 2 1 1 1 1 4 2 5 1
output:
2 3
result:
ok 2 lines
Test #6:
score: 0
Accepted
time: 64ms
memory: 544516kb
input:
10 1 1 1 1 2 2 2 2 1 1 10 2 6 1 2 9 1 1 1 1 2 3 2 1 4 7 1 3 9 2 8 1 2 6 1 2 9 2 2 0 1
output:
1 3 3
result:
ok 3 lines
Test #7:
score: 0
Accepted
time: 76ms
memory: 544544kb
input:
8 8 8 9 7 7 7 7 9 10 1 1 7 1 1 4 1 0 4 1 0 7 1 2 5 1 0 6 1 3 6 1 1 5 1 3 4 1 0 7
output:
10 9 10 11 9 10 9 9 8 11
result:
ok 10 lines
Test #8:
score: 0
Accepted
time: 88ms
memory: 544500kb
input:
8 8 8 8 8 9 8 7 7 10 1 2 7 1 2 6 1 3 7 1 0 5 1 1 4 1 0 7 1 3 4 1 0 6 1 0 4 1 2 5
output:
10 10 10 10 10 11 9 10 10 10
result:
ok 10 lines
Test #9:
score: 0
Accepted
time: 84ms
memory: 544472kb
input:
5 2 1 1 3 4 5 1 0 4 2 2 3 1 2 4 2 1 2 1 0 2
output:
5 5 4
result:
ok 3 lines
Test #10:
score: 0
Accepted
time: 120ms
memory: 544456kb
input:
7 1 1 1 1 2 2 2 5 1 0 6 1 2 4 2 6 4 1 4 6 1 0 6
output:
4 3 4 5
result:
ok 4 lines
Test #11:
score: 0
Accepted
time: 121ms
memory: 544608kb
input:
10 6 5 3 1 6 7 7 2 5 3 10 1 0 5 1 5 7 2 9 7 2 6 5 1 8 9 1 0 8 2 8 9 2 9 7 2 8 6 2 8 9
output:
7 8 7 7
result:
ok 4 lines
Test #12:
score: 0
Accepted
time: 104ms
memory: 544488kb
input:
10 4 4 4 2 2 2 2 2 2 2 10 1 2 8 2 6 1 2 0 2 1 7 8 2 6 3 2 8 2 1 1 8 1 1 3 1 7 9 2 2 5
output:
5 3 5 5 3
result:
ok 5 lines
Test #13:
score: 0
Accepted
time: 125ms
memory: 544476kb
input:
8 10 7 7 6 6 7 8 8 10 1 0 7 2 5 6 2 3 7 2 1 6 1 2 4 2 6 6 2 2 6 2 7 9 2 4 7 1 0 7
output:
11 8 11
result:
ok 3 lines
Test #14:
score: 0
Accepted
time: 80ms
memory: 544916kb
input:
8 9 9 8 8 7 7 7 7 10 1 0 7 2 6 9 1 0 7 2 0 7 2 3 7 1 0 7 2 5 8 2 1 7 2 7 9 1 0 7
output:
11 10 10 11
result:
ok 4 lines
Test #15:
score: 0
Accepted
time: 131ms
memory: 544748kb
input:
10 1 7 3 2 10 10 2 8 1 8 10 1 0 3 2 0 6 2 3 3 1 1 7 2 4 3 2 1 2 1 5 6 2 9 10 1 5 9 2 1 4
output:
7 11 10 10
result:
ok 4 lines
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #16:
score: 6
Accepted
time: 142ms
memory: 545976kb
input:
600 1 1 2 2 1 2 1 2 1 1 1 1 2 2 1 2 1 2 1 1 2 1 2 2 2 2 2 2 1 1 2 2 1 1 2 1 2 1 2 2 1 1 2 2 1 2 2 1 1 2 1 1 1 2 2 1 2 1 2 2 2 2 1 2 1 1 1 1 2 1 2 1 2 2 2 1 1 2 2 1 1 1 2 2 2 2 1 2 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 2 2 2 1 2 1 2 2 1 2 1 2 1 1 1 2 1 2 1 2 1 2 1 1 2 2 1 1 1 1 1 2 2 1 1 2 2 2 1 2 1 1 2 2 2 ...
output:
5 5 5 5 5 5 5 5 5 5 5 4 5 5 5 5 5 5 5 5 5 5 5 5 5 4 5 5 5 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 4 5 5 5 5 5 5 5 5 5 5 5 4 5 5 4 5 5 5 5 5 5 5 5 5 5 5 3 5 5 5 5 5 5 4 4 5 2 5 5 5 5 5 4 5 5 5 3 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 ...
result:
ok 600 lines
Test #17:
score: -6
Wrong Answer
time: 119ms
memory: 545968kb
input:
600 2 2 1 2 2 1 2 2 2 2 1 1 2 1 2 1 1 2 1 1 1 2 2 1 1 2 1 1 1 1 1 1 1 1 1 2 1 2 2 2 2 2 2 2 1 1 1 1 1 1 2 2 1 2 1 1 1 1 2 1 2 1 2 2 1 2 2 1 1 1 1 1 1 2 1 1 1 2 1 1 2 1 1 2 2 2 1 2 2 2 2 2 2 1 1 2 1 1 2 2 2 2 2 1 2 1 2 1 1 1 2 1 2 1 2 2 1 2 2 1 1 2 1 2 2 1 2 1 1 2 1 1 1 2 1 1 1 1 2 2 1 2 1 2 2 2 2 1 ...
output:
5 5 5 5 5 5 5 5 5 4 4 5 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 2 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 3 5 5 5 5 5 5 5 5 5 5 5 4 5 5 5 5 5 5 5 5 5 5 4 5 5 5 5 4 3 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 4 5 5 5 5 5 ...
result:
wrong answer 103rd lines differ - expected: '5', found: '4'
Subtask #3:
score: 0
Wrong Answer
Test #31:
score: 0
Wrong Answer
time: 165ms
memory: 552200kb
input:
4000 1 1 1 1 1 1 1 1 2 2 2 2 1 1 1 1 2 2 2 2 1 1 1 1 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 2 2 2 2 1 1 1 1 2 2 2 2...
output:
11 12 12 11 10 11 10 11 12 10 9 10 9 9 9 12 11 10 11 9 12 8 9 10 11 12 10 12 10 8 9 10 10 11 10 11 11 11 9 8 5 10 9 9 10 7 10 10 8 9 9 10 10 10 9 10 10 10 6 6 10 9 10 10 8 9 8 9 10 10 9 10 10 9 8 9 9 10 10 9 9 9 8 9 9 8 7 8 10 10 8 8 10 10 8 10 9 6 7 9 9 9 9 7 9 9 9 9 9 9 9 8 9 9 9 9 8 8 8 9 9 8 9 9...
result:
wrong answer 1933rd lines differ - expected: '6', found: '5'
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #5:
score: 0
Skipped
Dependency #3:
0%
Subtask #6:
score: 0
Wrong Answer
Test #69:
score: 14
Accepted
time: 2024ms
memory: 744708kb
input:
100000 2 10 6 3 5 4 2 6 9 3 8 3 9 6 9 8 8 9 4 6 5 10 7 1 2 5 5 2 7 3 5 10 5 6 7 5 9 10 6 10 7 3 2 1 7 8 4 4 3 10 1 6 9 9 6 9 6 1 6 4 8 5 5 6 8 3 3 7 6 6 3 5 5 9 5 5 7 10 7 3 10 1 4 2 3 6 9 2 7 2 8 10 4 5 2 6 7 1 8 2 8 3 3 10 9 8 6 6 9 6 4 5 8 4 10 10 4 1 6 4 4 3 9 4 7 7 2 8 8 7 10 6 8 2 1 4 2 2 5 2 ...
output:
12 11 11 12 12 12 11 12 12 12 12 12 11 12 12 12 12 12 12 12 12 12 12 12 12 11 12 12 11 10 12 12 12 12 12 12 12 12 12 12 12 12 12 11 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 11 12 12 12 12 11 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 11 12 12 12 12 12 12 12 12 12 12 12 ...
result:
ok 100000 lines
Test #70:
score: 0
Accepted
time: 1918ms
memory: 744932kb
input:
100000 3 4 5 6 10 5 6 2 2 2 5 3 7 1 2 1 10 7 6 5 1 10 6 8 4 6 10 5 6 2 9 7 2 9 7 9 6 2 6 1 9 6 6 4 1 5 4 2 10 8 7 5 2 1 4 10 7 10 10 8 9 10 7 7 3 8 6 8 4 5 5 4 7 8 5 5 6 3 5 8 6 7 1 1 5 2 6 5 2 6 4 1 9 4 8 3 4 5 2 1 2 4 8 8 5 9 1 1 1 2 9 7 7 2 2 2 2 6 2 7 9 7 9 4 1 3 4 2 6 1 6 9 1 8 2 4 3 2 4 2 10 7...
output:
12 12 12 12 12 12 12 12 11 12 12 12 11 12 12 12 12 12 12 12 12 12 12 11 12 12 12 12 12 12 12 12 12 11 12 11 12 12 12 11 12 12 12 10 12 12 12 12 12 12 12 11 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 11 12 12 11 12 11 12 12 12 11 11 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 ...
result:
ok 100000 lines
Test #71:
score: 0
Accepted
time: 2102ms
memory: 748076kb
input:
100000 3 3 3 3 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 1 1 1 1 2 2 2 2 3 3 3 3 2 2 2 2 3 3 3 3 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 1 1 1...
output:
17 13 17 18 17 17 17 17 13 18 15 15 17 14 17 14 17 17 17 18 16 16 14 16 16 17 16 17 14 14 18 16 15 17 16 15 16 16 16 17 16 16 18 15 18 16 17 17 12 18 16 18 16 15 15 14 17 16 16 14 16 17 13 18 17 15 18 16 17 16 17 14 13 18 17 17 17 18 17 14 15 15 15 16 17 17 17 17 16 18 16 18 17 18 17 18 14 16 18 10 ...
result:
ok 100000 lines
Test #72:
score: 0
Accepted
time: 1922ms
memory: 747612kb
input:
100000 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 3 3 3 3 1 1 1 1 1 1 1 1 3 3 3 3 1 1 1 1 2 2 2 2 1 1 1 1 3 3 3 3 3 3 3 3 1 1 1 1 2 2 2 2 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 1 1 1 1 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1...
output:
16 18 18 16 15 18 18 8 17 16 17 18 17 14 17 17 17 15 15 17 14 17 14 17 16 17 17 17 18 18 16 16 15 18 18 17 14 18 16 12 17 17 16 16 16 16 15 18 16 18 17 16 14 18 18 17 16 18 17 18 12 17 16 17 17 15 17 17 16 18 17 16 15 14 17 17 14 13 16 15 17 16 16 14 17 15 16 17 17 16 18 18 15 17 18 18 17 18 17 10 1...
result:
ok 100000 lines
Test #73:
score: -14
Wrong Answer
time: 2006ms
memory: 750520kb
input:
100000 4 4 4 4 4 4 4 4 4 4 3 3 3 3 3 3 3 1 1 1 1 1 1 3 3 3 3 3 3 3 4 4 4 4 4 4 4 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1...
output:
10 10 10 10 10 9 10 10 10 10 10 10 10 10 10 10 10 9 10 10 10 9 10 10 10 10 10 10 10 10 10 10 8 10 10 10 10 10 10 10 10 10 10 10 10 9 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 8 10 10 10 10 10 10 10 10 10 9 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 1...
result:
wrong answer 4561st lines differ - expected: '9', found: '8'
Subtask #7:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%