# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
596863 | 2022-07-15T08:14:54 Z | 조영욱(#8449) | Fish 2 (JOI22_fish2) | C++17 | 4000 ms | 3304 KB |
#include <bits/stdc++.h> using namespace std; int le[100001]; int ri[100001]; int arr[100001]; long long psum[100001]; int n; int q; typedef pair<int,int> P; vector<P> vec; bool win[100001]; int main(void) { scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&arr[i]); } stack<int> s; for(int i=1;i<=n;i++) { psum[i]=psum[i-1]+arr[i]; while (!s.empty()&&arr[s.top()]<=arr[i]) { s.pop(); } if (s.empty()) { le[i]=-1; } else { le[i]=s.top(); } s.push(i); } while (!s.empty()) { s.pop(); } for(int i=n;i>0;i--) { vec.push_back(P(arr[i],i)); while (!s.empty()&&arr[s.top()]<arr[i]) { s.pop(); } if (s.empty()) { ri[i]=-1; } else { ri[i]=s.top(); } s.push(i); } sort(vec.begin(),vec.end()); reverse(vec.begin(),vec.end()); scanf("%d",&q); for(int ind=0;ind<q;ind++) { int t,l,r; scanf("%d %d %d",&t,&l,&r); if (t==1) { vec.clear(); arr[l]=r; stack<int> s; for(int i=1;i<=n;i++) { psum[i]=psum[i-1]+arr[i]; while (!s.empty()&&arr[s.top()]<=arr[i]) { s.pop(); } if (s.empty()) { le[i]=-1; } else { le[i]=s.top(); } s.push(i); } while (!s.empty()) { s.pop(); } for(int i=n;i>0;i--) { vec.push_back(P(arr[i],i)); while (!s.empty()&&arr[s.top()]<arr[i]) { s.pop(); } if (s.empty()) { ri[i]=-1; } else { ri[i]=s.top(); } s.push(i); } for(int i=0;i<vec.size();i++) { if (vec[i].second==l) { vec.erase(vec.begin()+i); break; } } for(int i=0;i<=vec.size();i++) { if (i==vec.size()) { vec.insert(vec.begin()+i,P(arr[l],l)); break; } if (P(arr[l],l)>vec[i]) { vec.insert(vec.begin()+i,P(arr[l],l)); break; } } } else { int ret=0; for(int i=0;i<vec.size();i++) { int now=vec[i].second; win[now]=false; if (now<l||now>r) { continue; } if (le[now]!=-1&&le[now]>=l&&!win[le[now]]) { continue; } if (ri[now]!=-1&&ri[now]<=r&&!win[ri[now]]) { continue; } int lef=((le[now]==-1||le[now]<l)?l:le[now]+1); int rig=((ri[now]==-1||ri[now]>r)?r:ri[now]-1); //if (ind==1) printf("%d %d\n",lef,rig); long long val=psum[rig]-psum[lef-1]; if (lef==l&&rig==r) { win[now]=true; ret++; } else if (lef!=l&&arr[le[now]]<=val) { win[now]=true; ret++; } else if (rig!=r&&arr[ri[now]]<=val) { win[now]=true; ret++; } } printf("%d\n",ret); } } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 24 ms | 3276 KB | Output is correct |
3 | Correct | 26 ms | 3240 KB | Output is correct |
4 | Correct | 26 ms | 3276 KB | Output is correct |
5 | Correct | 22 ms | 3276 KB | Output is correct |
6 | Correct | 24 ms | 3276 KB | Output is correct |
7 | Correct | 21 ms | 3276 KB | Output is correct |
8 | Correct | 25 ms | 3260 KB | Output is correct |
9 | Correct | 20 ms | 3276 KB | Output is correct |
10 | Correct | 24 ms | 3276 KB | Output is correct |
11 | Correct | 18 ms | 3276 KB | Output is correct |
12 | Correct | 28 ms | 3276 KB | Output is correct |
13 | Correct | 25 ms | 3304 KB | Output is correct |
14 | Correct | 36 ms | 3172 KB | Output is correct |
15 | Correct | 26 ms | 3256 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 24 ms | 3276 KB | Output is correct |
3 | Correct | 26 ms | 3240 KB | Output is correct |
4 | Correct | 26 ms | 3276 KB | Output is correct |
5 | Correct | 22 ms | 3276 KB | Output is correct |
6 | Correct | 24 ms | 3276 KB | Output is correct |
7 | Correct | 21 ms | 3276 KB | Output is correct |
8 | Correct | 25 ms | 3260 KB | Output is correct |
9 | Correct | 20 ms | 3276 KB | Output is correct |
10 | Correct | 24 ms | 3276 KB | Output is correct |
11 | Correct | 18 ms | 3276 KB | Output is correct |
12 | Correct | 28 ms | 3276 KB | Output is correct |
13 | Correct | 25 ms | 3304 KB | Output is correct |
14 | Correct | 36 ms | 3172 KB | Output is correct |
15 | Correct | 26 ms | 3256 KB | Output is correct |
16 | Correct | 1 ms | 212 KB | Output is correct |
17 | Execution timed out | 4040 ms | 3288 KB | Time limit exceeded |
18 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 24 ms | 3276 KB | Output is correct |
3 | Correct | 26 ms | 3240 KB | Output is correct |
4 | Correct | 26 ms | 3276 KB | Output is correct |
5 | Correct | 22 ms | 3276 KB | Output is correct |
6 | Correct | 24 ms | 3276 KB | Output is correct |
7 | Correct | 21 ms | 3276 KB | Output is correct |
8 | Correct | 25 ms | 3260 KB | Output is correct |
9 | Correct | 20 ms | 3276 KB | Output is correct |
10 | Correct | 24 ms | 3276 KB | Output is correct |
11 | Correct | 18 ms | 3276 KB | Output is correct |
12 | Correct | 28 ms | 3276 KB | Output is correct |
13 | Correct | 25 ms | 3304 KB | Output is correct |
14 | Correct | 36 ms | 3172 KB | Output is correct |
15 | Correct | 26 ms | 3256 KB | Output is correct |
16 | Incorrect | 1 ms | 212 KB | Output isn't correct |
17 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |