제출 #153013

#제출 시각아이디문제언어결과실행 시간메모리
153013arnold518Examination (JOI19_examination)C++14
100 / 100
439 ms15220 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 1e5; struct Data { int X, Y, Z, id; }; int N, Q, ans[MAXN+10]; pii A[MAXN+10]; Data B[MAXN+10]; struct Query { int x, y, num; }; vector<Query> todo; vector<int> xcomp, ycomp; int getxcomp(int x) { return lower_bound(xcomp.begin(), xcomp.end(), x)-xcomp.begin()+1; } int getycomp(int y) { return lower_bound(ycomp.begin(), ycomp.end(), y)-ycomp.begin()+1; } struct BIT { int tree[MAXN+10]; BIT() { memset(tree, 0, sizeof(tree)); } void update(int i) { for(; i<=ycomp.size(); i+=(i&-i)) tree[i]++; } int query(int i) { int ret=0; for(; i>0; i-=(i&-i)) ret+=tree[i]; return ret; } void fflush(int i) { for(; i<=ycomp.size(); i+=(i&-i)) tree[i]=0; } } bit; void solve(int s, int e) { int i, j; if(s+1==e) return; int mid=s+e>>1; solve(s, mid); vector<Query> a, b; for(i=s; i<mid; i++) if(todo[i].num==0) b.push_back(todo[i]); for(i=mid; i<e; i++) if(todo[i].num!=0) a.push_back(todo[i]); sort(a.begin(), a.end(), [&](const Query &p, const Query &q) { return p.x>q.x; }); sort(b.begin(), b.end(), [&](const Query &p, const Query &q) { return p.x>q.x; }); for(i=0, j=0; i<a.size(); i++) { for(; j<b.size() && b[j].x>=a[i].x; j++) bit.update(b[j].y); ans[a[i].num]+=bit.query(ycomp.size())-bit.query(a[i].y-1); } for(j=0; j<b.size(); j++) bit.fflush(b[j].y); solve(mid, e); } int main() { int i, j; scanf("%d%d", &N, &Q); for(i=1; i<=N; i++) scanf("%d%d", &A[i].first, &A[i].second), xcomp.push_back(A[i].first), ycomp.push_back(A[i].second); for(i=1; i<=Q; i++) scanf("%d%d%d", &B[i].X, &B[i].Y, &B[i].Z), B[i].id=i; sort(xcomp.begin(), xcomp.end()); xcomp.erase(unique(xcomp.begin(), xcomp.end()), xcomp.end()); sort(ycomp.begin(), ycomp.end()); ycomp.erase(unique(ycomp.begin(), ycomp.end()), ycomp.end()); sort(A+1, A+N+1, [&](const pii &p, const pii &q) { return p.first+p.second>q.first+q.second; }); sort(B+1, B+Q+1, [&](const Data &p, const Data &q) { return p.Z>q.Z; }); int it=1; for(i=1; i<=Q; i++) { for(; it<=N && A[it].first+A[it].second>=B[i].Z; it++) todo.push_back({getxcomp(A[it].first), getycomp(A[it].second), 0}); todo.push_back({getxcomp(B[i].X), getycomp(B[i].Y), B[i].id}); } solve(0, todo.size()); for(i=1; i<=Q; i++) printf("%d\n", ans[i]); }

컴파일 시 표준 에러 (stderr) 메시지

examination.cpp: In member function 'void BIT::update(int)':
examination.cpp:27:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     void update(int i) { for(; i<=ycomp.size(); i+=(i&-i)) tree[i]++; }
                                ~^~~~~~~~~~~~~~
examination.cpp: In member function 'void BIT::fflush(int)':
examination.cpp:29:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     void fflush(int i) { for(; i<=ycomp.size(); i+=(i&-i)) tree[i]=0; }
                                ~^~~~~~~~~~~~~~
examination.cpp: In function 'void solve(int, int)':
examination.cpp:37:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid=s+e>>1;
             ~^~
examination.cpp:47:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0, j=0; i<a.size(); i++)
                   ~^~~~~~~~~
examination.cpp:49:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(; j<b.size() && b[j].x>=a[i].x; j++) bit.update(b[j].y);
               ~^~~~~~~~~
examination.cpp:52:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(j=0; j<b.size(); j++) bit.fflush(b[j].y);
              ~^~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:58:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
examination.cpp:60:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &N, &Q);
     ~~~~~^~~~~~~~~~~~~~~~
examination.cpp:61:94: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(i=1; i<=N; i++) scanf("%d%d", &A[i].first, &A[i].second), xcomp.push_back(A[i].first), ycomp.push_back(A[i].second);
                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:62:67: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(i=1; i<=Q; i++) scanf("%d%d%d", &B[i].X, &B[i].Y, &B[i].Z), B[i].id=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...