# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
27401 | 2017-07-12T11:58:58 Z | tlwpdus | Ruka (COI15_ruka) | C++11 | 1186 ms | 9332 KB |
#include <bits/stdc++.h> using namespace std; int n, m, MAXN = 1e8+2, bia = 5e7+1; struct BIT { unordered_map<int,int> bit; void upd(int idx, int val) { idx += bia; while(idx<=MAXN) { if (bit.find(idx)==bit.end()) bit[idx] = val; else bit.find(idx)->second += val; idx += idx&(-idx); } } int getv(int idx) { int res = 0; idx += bia; while(idx>0) { res += (bit.find(idx)==bit.end())?0:bit[idx]; idx -= idx&(-idx); } return res; } }; struct bs { BIT bitu, bitd; int arr[100100]; int cur, sum, b; bs() {cur=b=0;sum=1;} void init() { int i, res = 1+arr[0]; for (i=1;i<n;i++) { int p = res, q = res+arr[i]; if (p>q) swap(p,q); bitd.upd(p,1); bitd.upd(q,-1); res += arr[i]; } } void B() { if (!cur) return; int p = sum+b, q = sum+arr[cur]+b; if (p>q) swap(p,q); bitd.upd(p,1); bitd.upd(q,-1); cur--; sum -= arr[cur]; p = sum; q = sum+arr[cur]; if (p>q) swap(p,q); bitu.upd(p,-1); bitu.upd(q,1); } void F() { if (cur==n-1) return; int p = sum, q = sum+arr[cur]; if (p>q) swap(p,q); bitu.upd(p,1); bitu.upd(q,-1); sum += arr[cur]; cur++; p = sum+b; q = sum+arr[cur]+b; if (p>q) swap(p,q); bitd.upd(p,-1); bitd.upd(q,1); } int Q() { return bitu.getv(0)+bitd.getv(b)+(1LL*sum*(sum+arr[cur])<0); } void C(int nx) { b += arr[cur]-nx; arr[cur] = nx; } } x, y; int main(){ int i; scanf("%d",&n); for (i=0;i<n;i++) scanf("%d%d",&x.arr[i],&y.arr[i]); x.init(); y.init(); scanf("%d",&m); for (i=0;i<m;i++) { char ch; scanf(" %c",&ch); if (ch=='B') { x.B(); y.B(); } else if (ch=='F') { x.F(); y.F(); } else if (ch=='Q') { printf("%d\n",x.Q()+y.Q()); } else { int a, b; scanf("%d%d",&a,&b); x.C(a); y.C(b); } } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 2940 KB | Output is correct |
2 | Correct | 3 ms | 2940 KB | Output is correct |
3 | Correct | 3 ms | 2940 KB | Output is correct |
4 | Correct | 3 ms | 2808 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 2940 KB | Output is correct |
2 | Correct | 3 ms | 2940 KB | Output is correct |
3 | Correct | 3 ms | 2940 KB | Output is correct |
4 | Correct | 3 ms | 2808 KB | Output is correct |
5 | Correct | 333 ms | 5300 KB | Output is correct |
6 | Correct | 269 ms | 4736 KB | Output is correct |
7 | Correct | 229 ms | 3760 KB | Output is correct |
8 | Correct | 213 ms | 3784 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 2940 KB | Output is correct |
2 | Correct | 3 ms | 2940 KB | Output is correct |
3 | Correct | 3 ms | 2940 KB | Output is correct |
4 | Correct | 3 ms | 2808 KB | Output is correct |
5 | Correct | 333 ms | 5300 KB | Output is correct |
6 | Correct | 269 ms | 4736 KB | Output is correct |
7 | Correct | 229 ms | 3760 KB | Output is correct |
8 | Correct | 213 ms | 3784 KB | Output is correct |
9 | Correct | 846 ms | 8756 KB | Output is correct |
10 | Correct | 1186 ms | 9332 KB | Output is correct |
11 | Correct | 843 ms | 7516 KB | Output is correct |
12 | Correct | 679 ms | 7116 KB | Output is correct |