Submission #715236

#TimeUsernameProblemLanguageResultExecution timeMemory
715236ismayilExamination (JOI19_examination)C++17
20 / 100
295 ms4428 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; const int MAX = 1e5; int bit[MAX + 1]; void update(int pos, int val){ for(int i = pos; i <= MAX; i = i | (i + 1)){ bit[i] += val; } } int ask(int pos){ int res = 0; for(int i = pos; i >= 0; i = (i & (i + 1)) - 1){ res += bit[i]; } return res; } int ask(int l, int r){ if(l == 0) return ask(r); return ask(r) - ask(l - 1); } struct query{ int x, y, idx; bool operator<(query other){ return x < other.x; } }; int main(){ int n, m; cin>>n>>m; vector<pair<int, int>> p; for(int i = 0; i < n; i++){ int x, y; cin>>x>>y; p.push_back({x, y}); } sort(p.begin(), p.end()); vector<query> queries; for(int i = 0; i < m; i++){ int x, y, z; cin>>x>>y>>z; queries.push_back({x, y, i}); } sort(queries.begin(), queries.end()); int ans[m]; int idx = n - 1; for (int i = m - 1; i >= 0; i--) { while(idx >= 0 && queries[i].x <= p[idx].first){ update(p[idx].second, 1); idx--; } ans[queries[i].idx] = ask(queries[i].y, MAX); } for (int i = 0; i < m; i++) cout<<ans[i]<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...