제출 #879984

#제출 시각아이디문제언어결과실행 시간메모리
879984cpptowinExamination (JOI19_examination)C++17
100 / 100
1107 ms27132 KiB
#include<bits/stdc++.h> #define fo(i,d,c) for(int i=d;i<=c;i++) #define fod(i,c,d) for(int i=c;i>=d;i--) #define maxn 1000010 #define N 1010 #define fi first #define se second #define pb emplace_back #define en cout<<"\n"; //#define int long long #define inf 1000000000 #define pii pair<int,int> #define vii vector<pii> #define lb(x) x&-x #define bit(i,j) ((i>>j)&1) #define offbit(i,j) (i^(1<<j)) #define onbit(i,j) (i|(1<<j)) #define vi vector<int> template <typename T1, typename T2> bool minimize(T1 &a, T2 b) { if (a > b) { a = b; return true; } return false; } template <typename T1, typename T2> bool maximize(T1 &a, T2 b) { if (a < b) { a = b; return true; } return false; } using namespace std; struct BIT { int t[maxn]; void up(int x,int val) { x++; for( ; x < maxn ; x += lb(x)) t[x] += val; } int get(int x) { int ans = 0; for( ; x ; x -= lb(x)) ans += t[x]; return ans; } } t1; const int BLOCK = 500; struct query { int A, B, C, id; bool operator < (query y) { return make_pair(A / BLOCK, B) < make_pair(y.A / BLOCK, y.B); } }; vector<query> v; int n,q; vii v1,v2; vi v3; int nen[maxn],s[maxn],t[maxn],cnt[maxn],ans[maxn]; main() { #define name "TASK" if(fopen(name".inp","r")) { freopen(name".inp","r",stdin); freopen(name".out","w",stdout); } ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> q; fo(i,1,n) { cin >> s[i] >> t[i]; v1.push_back({s[i], i}); v2.push_back({t[i], i}); v3.push_back(s[i] + t[i]); } sort(v1.begin(),v1.end()); sort(v2.begin(),v2.end()); sort(v3.begin(),v3.end()); // for(int it : v3) cout << it << ' '; // en; fo(i,1,n) nen[i] = lower_bound(v3.begin(),v3.end(),s[i] + t[i]) - v3.begin(); fo(i,1,q) { int A,B,C; cin >> A >> B >> C; // cout << A << ' ' << B << ' ' << C << "\n"; int x = lower_bound(v1.begin(),v1.end(),make_pair(A, 0)) - v1.begin(); int y = lower_bound(v2.begin(),v2.end(),make_pair(B,0)) - v2.begin(); int z = lower_bound(v3.begin(),v3.end(),C) - v3.begin(); // cout << x << ' ' << y << ' ' << z << "\n"; v.push_back({x,y,z,i}); } sort(v.begin(),v.end()); int l = n,r = n; // fo(i,0,n - 1) cout << cnt[i] << ' ' ; // en; for(auto [A,B,C,id] : v) { // cout << A << ' ' << B << ' ' << C << ' ' << id << ' ' << l << ' ' << r << "\n"; while(A < l) { cnt[v1[l - 1].se]++; // cout << v1[l - 1].se << "\n"; if(cnt[v1[l - 1].se] == 2) t1.up(nen[v1[l - 1].se],1); l--; } while(A > l) { // cout << "ccc"; // en; cnt[v1[l].se]--; if(cnt[v1[l].se] == 1) t1.up(nen[v1[l].se],-1); l++; } while(B < r) { cnt[v2[r - 1].se]++; if(cnt[v2[r - 1].se] == 2) t1.up(nen[v2[r - 1].se],1); r--; } while(B > r) { cnt[v2[r].se]--; if(cnt[v2[r].se] == 1) t1.up(nen[v2[r].se],-1); r++; } // cout << l << ' ' << r << "\n"; // fo(i,1,n) cout << cnt[i] << ' '; // en; ans[id] = t1.get(maxn - 3) - t1.get(C); } fo(i,1,q) cout << ans[i] << "\n"; }

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

examination.cpp:67:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   67 | main()
      | ^~~~
examination.cpp: In function 'int main()':
examination.cpp:72:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |         freopen(name".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
examination.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |         freopen(name".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...