# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
48258 | 2018-05-11T07:17:46 Z | choikiwon | 허수아비 (JOI14_scarecrows) | C++17 | 4000 ms | 262144 KB |
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; const int MN = 200010; const int SQ = 300; const int BS = (MN + SQ - 1) / SQ; int N; pii P[MN]; vector<pii> X, Y; int invx[MN], invy[MN]; vector<pii> stk[BS]; int solve(int x) { int p; for(int i = 0; i < BS; i++) if(i * SQ >= P[x].second) { p = i; break; } vector<pii> tmp; for(int i = P[x].second + 1; i < p * SQ; i++) { if(invy[i] > x) tmp.push_back({ invy[i], i }); } if(tmp.size() == 0) { return stk[p].size(); } sort(tmp.begin(), tmp.end()); vector<pii> tstk; for(int i = (int)tmp.size() - 1; i >= 0; i--) { while(tstk.size() && tstk.back().second >= tmp[i].second) tstk.pop_back(); tstk.push_back(tmp[i]); } int s = 0, e = (int)stk[p].size() - 1, k = -1; while(s <= e) { int m = (s + e)>>1; if(stk[p][m].first < tstk[0].first) { p = m; s = m + 1; } else e = m - 1; } return k + 1 + (int)tstk.size(); } int main() { scanf("%d", &N); for(int i = 0; i < N; i++) { scanf("%d %d", &P[i].first, &P[i].second); X.push_back({ P[i].first, i }); Y.push_back({ P[i].second, i }); } sort(X.begin(), X.end()); sort(Y.begin(), Y.end()); for(int i = 0; i < N; i++) { P[ X[i].second ].first = i; P[ Y[i].second ].first = i; } for(int i = 0; i < N; i++) { invx[ P[i].first ] = P[i].second; invy[ P[i].second ] = P[i].first; } sort(P, P + N); ll ans = 0; for(int i = N - 1; i >= 0; i--) { ans += solve(i); for(int j = 0; j < BS; j++) { if(j * SQ > P[i].second) break; while(stk[j].size() && stk[j].back().second >= P[i].second) stk[j].pop_back(); stk[j].push_back(P[i]); } } printf("%lld", ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 632 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 17 ms | 1396 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 4046 ms | 262144 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |