Submission #233175

#TimeUsernameProblemLanguageResultExecution timeMemory
233175Shafin666Examination (JOI19_examination)C++14
100 / 100
629 ms16352 KiB
#include <bits/stdc++.h> #define pb push_back #define pii pair<int, int> #define nyan "(=^・ω・^=)" #define read_input freopen("in.txt","r", stdin) #define print_output freopen("out.txt","w", stdout) typedef long long ll; typedef long double ld; using namespace std; const int maxn = 2e5+10; int n, q; vector<int> X, Y; int ans[maxn]; struct event { int x, y, z, idx; }; vector<event> events; struct tree { vector<int> a; tree() : a(maxn+1) {} void add(int x, int v) { for(; x; x -= x & -x) a[x] += v; } int query(int x) { int ret = 0; for(; x < a.size(); x += x & -x) ret += a[x]; return ret; } } bit; void trim(vector<int> &v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); } void solve(int l, int r) { if(l == r) return; int mid = l + r >> 1; solve(l, mid); vector<event> qry, upd; for(int i = l; i <= mid; i++) { if(events[i].idx == 0) upd.pb(events[i]); } for(int i = mid+1; i <= r; i++) { if(events[i].idx) qry.pb(events[i]); } sort(qry.begin(), qry.end(), [] (event a, event b) {return a.x > b.x;}); sort(upd.begin(), upd.end(), [] (event a, event b) {return a.x > b.x;}); for(int i = 0, j = 0; i < qry.size(); i++) { while(j < upd.size() && upd[j].x >= qry[i].x) { bit.add(upd[j].y, 1); j++; } ans[qry[i].idx] += bit.query(qry[i].y); } for(auto e : upd) { int last = qry.empty()? 1e9+7 : qry[qry.size()-1].x; if(e.x < last) break; bit.add(e.y, -1); } solve(mid+1, r); } int main() { cin >> n >> q; for(int i = 1; i <= n; i++) { int x, y; cin >> x >> y; X.pb(x); Y.pb(y); event e = {x, y, x+y, 0}; events.pb(e); } for(int i = 1; i <= q; i++) { int x, y, z; cin >> x >> y >> z; X.pb(x); Y.pb(y); event e = {x, y, z, i}; events.pb(e); } trim(X); trim(Y); for(int i = 0; i < events.size(); i++) { event e = events[i]; e.x = lower_bound(X.begin(), X.end(), e.x) - X.begin() + 1; e.y = lower_bound(Y.begin(), Y.end(), e.y) - Y.begin() + 1; events[i] = e; } sort(events.begin(), events.end(), [] (event a, event b) { if(a.z == b.z) return a.idx < b.idx; return a.z > b.z; }); solve(0, events.size()-1); for(int i = 1; i <= q; i++) printf("%d\n", ans[i]); return 0; }

Compilation message (stderr)

examination.cpp: In member function 'int tree::query(int)':
examination.cpp:31:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(; x < a.size(); x += x & -x)
               ~~^~~~~~~~~~
examination.cpp: In function 'void solve(int, int)':
examination.cpp:45:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid = l + r >> 1;
               ~~^~~
examination.cpp:62:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0, j = 0; i < qry.size(); i++) {
                           ~~^~~~~~~~~~~~
examination.cpp:63:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(j < upd.size() && upd[j].x >= qry[i].x) {
               ~~^~~~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:100:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < events.size(); i++) {
                    ~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...