Submission #310912

#TimeUsernameProblemLanguageResultExecution timeMemory
310912vipghn2003Examination (JOI19_examination)C++14
100 / 100
1308 ms92000 KiB
#include <bits/stdc++.h> #define pii pair<int,int> #define fi first #define se second #define mp make_pair using namespace std; const int N=1e5+5; struct BIT2D { const int inf = 2e9; int n; vector<vector<int>>nodes,f; void fakeUpdate(int u, int v) { for (int x = u; x > 0; x -= x & -x) nodes[x].push_back(v); } void fakeGet(int u, int v) { for (int x = u; x <= n; x += x & -x) nodes[x].push_back(v); } void update(int u, int v) { for (int x = u; x > 0; x -= x & -x) { for (int y = upper_bound(nodes[x].begin(), nodes[x].end(), v) - nodes[x].begin(); y > 0; y -= y & -y) f[x][y]++; } } int get(int u, int v) { int res=0; for (int x = u; x <= n; x += x & -x) { for (int y = lower_bound(nodes[x].begin(), nodes[x].end(), v) - nodes[x].begin() + 1; y <= nodes[x].size(); y += y & -y) res += f[x][y]; } return res; } void init(int _n) { n = _n; nodes.assign(n + 5, {}); f.assign(n + 5, {}); } void normalize() { for(int i=1;i<=n;i++) { nodes[i].push_back(inf); sort(nodes[i].begin(), nodes[i].end()); f[i].resize(nodes[i].size()+3); } } } ft; int n,q,ans[N]; pair<int,int>stu[N]; vector<int>val; int compress(int x) { return lower_bound(val.begin(),val.end(),x)-val.begin()+1; } struct Q { int A, B, C, id; }; Q query[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin>>n>>q; for(int i=1;i<=n;i++) { cin>>stu[i].fi>>stu[i].se; val.push_back(stu[i].fi); val.push_back(stu[i].se); val.push_back(stu[i].fi+stu[i].se); } for(int i=1;i<=q;i++) { query[i].id=i; cin>>query[i].A>>query[i].B>>query[i].C; val.push_back(query[i].A); val.push_back(query[i].B); val.push_back(query[i].C); } sort(val.begin(),val.end()); val.erase(unique(val.begin(),val.end()),val.end()); ft.init(val.size()); sort(stu+1,stu+n+1); reverse(stu+1,stu+n+1); sort(query + 1, query + 1 + n, [&](const Q& x, const Q& y) { return x.A > y.A; }); int j=1; for(int i=1;i<=q;i++) { while(j<=n&&stu[j].fi>=query[i].A) { ft.fakeUpdate(compress(stu[j].se),compress(stu[j].fi+stu[j].se)); j++; } ft.fakeGet(compress(query[i].B),compress(query[i].C)); } ft.normalize(); j=1; for(int i=1;i<=q;i++) { while(j<=n&&stu[j].fi>=query[i].A) { ft.update(compress(stu[j].se),compress(stu[j].fi+stu[j].se)); j++; } ans[query[i].id]=ft.get(compress(query[i].B),compress(query[i].C)); } for(int i=1;i<=q;i++) cout<<ans[i]<<'\n'; }

Compilation message (stderr)

examination.cpp: In member function 'int BIT2D::get(int, int)':
examination.cpp:36:101: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |             for (int y = lower_bound(nodes[x].begin(), nodes[x].end(), v) - nodes[x].begin() + 1; y <= nodes[x].size(); y += y & -y)
      |                                                                                                   ~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...