Submission #287276

#TimeUsernameProblemLanguageResultExecution timeMemory
287276BlagojceExamination (JOI19_examination)C++11
2 / 100
3025 ms348928 KiB
#include <bits/stdc++.h> #define fr(i, n, m) for(int i = (n); i < (m); i ++) #define pb push_back #define st first #define nd second #define pq priority_queue #define all(x) begin(x), end(x) #include <time.h> #include <cmath> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; const int i_inf = 1e9; const ll inf = 1e18; const ll mod = 1000000007; const ld eps = 1e-13; const ld pi = 3.14159265359; mt19937 _rand(time(NULL)); clock_t timer = clock(); const int mxn = 2e5; const ll A = 911382323; const ll B = 972663749; int n, m; int s[mxn], t[mxn]; int a[mxn], b[mxn], c[mxn]; int ans[mxn]; int arr[mxn]; int range1; int range2; void compress(){ vector<pii> v; vector<pii> g; fr(i, 0, n){ v.pb({s[i], i+1}); g.pb({t[i], i+1}); } fr(i, 0, m){ v.pb({a[i],-i-1}); g.pb({b[i],-i-1}); } sort(all(v)); sort(all(g)); int nwv = 0; for(auto u : v){ nwv ++; if(u.nd > 0) s[u.nd-1] = nwv; if(u.nd < 0) a[-u.nd-1] = nwv; } range1 = nwv; nwv = 0; for(auto u : g){ nwv ++; if(u.nd > 0) t[u.nd-1] = nwv; if(u.nd < 0) b[-u.nd-1] = nwv; } range2 = nwv; } const int bsz = 400; int bit[500][mxn]; int cnt[bsz]; void update(int block, int k, int v){ while(k < mxn){ bit[block][k] += v; k += k&-k; } } int sum(int block, int k){ int s = 0; while(k > 0){ s += bit[block][k]; k -= k&-k; } return s; } void solve(){ cin >> n >> m; vector<int> v; fr(i, 0, n){ cin >> s[i] >> t[i]; v.pb(i); } sort(all(v), [](const int &i, const int &j){ return s[i]+t[i] > s[j] + t[j]; }); int oldsum[n]; fr(i, 0, n){ oldsum[i] = s[v[i]] + t[v[i]]; } vector<int> g; fr(i, 0, m){ cin >> a[i] >> b[i] >> c[i]; g.pb(i); } sort(all(g), [](const int &i, const int &j){ return c[i] > c[j]; }); compress(); int pos = 0; int totb = (range1+bsz-1)/bsz; for(auto u : g){ while(pos < n && oldsum[pos] >= c[u]){ arr[s[v[pos]]] = t[v[pos]]; int bi = (s[v[pos]]-1)/bsz; update(bi, t[v[pos]], +1); ++cnt[bi]; ++pos; } int bi = (a[u]-1)/bsz; int p = a[u]; while((p-1)/bsz == bi){ if(arr[p] >= b[u]) ans[u] ++; ++p; } fr(j, bi+1, totb+1){ ans[u] += cnt[j]-sum(j, b[u]-1); } } fr(i, 0, m){ cout<<ans[i]<<endl; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int tc = 1; //cin >> tc; while(tc--) solve(); }/* 10 1 41304 98327 91921 28251 85635 59191 30361 72671 28949 96958 99041 37826 10245 2726 19387 20282 60366 87723 95388 49726 52302 69501 66009*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...