Submission #443605

#TimeUsernameProblemLanguageResultExecution timeMemory
443605minhcoolExamination (JOI19_examination)C++17
0 / 100
3091 ms293592 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define fi first #define se second #define pb push_back #define hash hash1 #define index indexx #define foru(i, l, r) for(int i = l; i <= r; i++) #define ford(i, r, l) for(int i = r; i >= l; i--) typedef pair<int, int> ii; typedef pair<ii, int> iii; typedef pair<ii, ii> iiii; const int N = 2e5 + 5; const int oo = 1e18 + 7, mod = 1e9 + 7; const int hashy = 1e9 + 87; /* I think this is one of the easiest problems that you can give a guy if he knows segtree 2D */ // I think this will run as slow as f*ck, but it is sure O(1) lol struct hash{ int operator()(const ii&a)const{ return ((a.fi % hashy) << 30) | (a.se % hashy); } }; int n, q; vector<pair<int, ii>> students; vector<pair<iii, int>> queries; int answer[N]; int cnt; int IT[N * 20 * 20]; map<iiii, int> index; int cal(int x1, int y1, int x2, int y2){ if(index.find({{x1, y1}, {x2, y2}}) != index.end()) return index[{{x1, y1}, {x2, y2}}]; cnt++; return index[{{x1, y1}, {x2, y2}}] = cnt; } void updy(int ind, int lx, int rx, int ly, int ry, int posy, int val){ //cout << ind << " " << lx << " " << rx << " " << ly << " " << ry << "\n"; IT[ind] += val; if(ly == ry) return; int mid = (ly + ry) >> 1; if(posy <= mid) updy(cal(lx, rx, ly, mid), lx, rx, ly, mid, posy, val); else updy(cal(lx, rx, mid + 1, ry), lx, rx, mid + 1, ry, posy, val); } void updx(int ind, int lx, int rx, int posx, int posy, int val){ updy(ind, lx, rx, 1, (1LL << 20), posy, val); if(lx == rx) return; int mid = (lx + rx) >> 1; if(posx <= mid) updx(cal(lx, mid, 1, 1LL << 20), lx, mid, posx, posy, val); else updx(cal(mid + 1, rx, 1, 1LL << 20), mid + 1, rx, posx, posy, val); //int temp2 = cal(((long long)(mid + 1) << 30LL) + rx, 1LL << 31); } int gety(int lx, int rx, int ly, int ry, int Ly, int Ry){ if(ly > Ry || ry < Ly) return 0; if(ly >= Ly && ry <= Ry){ //cout << cal(((long long)lx << 20LL) + rx, ((long long)ly << 20LL) + ry) << " " << lx << " " << ly << " " << rx << " " << ry << " " << IT[cal(((long long)lx << 20LL) + rx, ((long long)ly << 20LL) + ry)] << "\n"; //if(IT[cal(lx, rx, ly, ry)]) cout << lx << " " << rx << " " << ly << " " << ry << " " << Ly << " " << Ry << "\n"; return IT[cal(lx, rx, ly, ry)]; } int mid = (ly + ry) >> 1; return gety(lx, rx, ly, mid, Ly, Ry) + gety(lx, rx, mid + 1, ry, Ly, Ry); } int getx(int lx, int rx, int Lx, int Rx, int Ly, int Ry){ if(lx > Rx || rx < Lx) return 0; if(lx >= Lx && rx <= Rx){ //cout << lx << " " << rx << "\n"; return gety(lx, rx, 1, 1LL << 20, Ly, Ry); } int mid = (lx + rx) >> 1; return getx(lx, mid, Lx, Rx, Ly, Ry) + getx(mid + 1, rx, Lx, Rx, Ly, Ry); } void process(){ cin >> n >> q; for(int i = 1; i <= n; i++){ int S, T; cin >> S >> T; students.pb({S + T, {S, T}}); } for(int i = 1; i <= q; i++){ int a, b, c; cin >> a >> b >> c; queries.pb({{{c, a}, b}, i}); } sort(students.begin(), students.end()); sort(queries.begin(), queries.end()); reverse(queries.begin(), queries.end()); cal(1, 1LL << 20, 1, 1LL << 20); //return; for(auto it : queries){ while(students.size() && it.fi.fi.fi <= students.back().fi){ updx(1, 1, 1LL << 20, students.back().se.fi, students.back().se.se, 1); students.pop_back(); } //cout << students.size() << "\n"; answer[it.se] = getx(1, 1LL << 20, it.fi.fi.se, 1LL << 20, it.fi.se, 1LL << 20); } for(int i = 1; i <= q; i++) cout << answer[i] << "\n"; } signed main(){ ios_base::sync_with_stdio(0); process(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...