Submission #750504

#TimeUsernameProblemLanguageResultExecution timeMemory
750504mars4Examination (JOI19_examination)C++17
0 / 100
1520 ms12796 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define ff first #define ss second #define ll int64_t #define ld long double #define nl cout<<"\n" #define i128 __int128_t #define all(v) v.begin(),v.end() #define mset(a,v) memset((a),(v),sizeof(a)) #define forn(i,a,b) for(int64_t i=int64_t(a);i<int64_t(b);++i) #define forb(i,a,b) for(int64_t i=int64_t(a);i>=int64_t(b);--i) #define fastio() ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define mod 1'000'000'007 #define mod2 998'244'353 #define inf 1'000'000'000'000'007 #define pi 3.14159265358979323846 template<class key,class cmp=std::less<key>> using ordered_set=tree<key,null_type,cmp,rb_tree_tag,tree_order_statistics_node_update>; template<class L,class R> ostream& operator<<(ostream& out,pair<L,R> &p) {return out<<"("<<p.ff<<", "<<p.ss<<")";} template<class T> ostream& operator<<(ostream& out,vector<T> &v) {out<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())out<<", ";out<<*it;}return out<<"]";} template<class T> ostream& operator<<(ostream& out,deque<T> &v) {out<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())out<<", ";out<<*it;}return out<<"]";} template<class T> ostream& operator<<(ostream& out,set<T> &s) {out<<"{";for(auto it=s.begin();it!=s.end();++it){if(it!=s.begin())out<<", ";out<<*it;}return out<<"}";} template<class T> ostream& operator<<(ostream& out,ordered_set<T> &s) {out<<"{";for(auto it=s.begin();it!=s.end();++it){if(it!=s.begin())out<<", ";out<<*it;}return out<<"}";} template<class L,class R> ostream& operator<<(ostream& out,map<L,R> &m) {out<<"{";for(auto it=m.begin();it!=m.end();++it){if(it!=m.begin())out<<", ";out<<*it;}return out<<"}";} void dbg_out() {cerr<<"]\n";} template<typename Head,typename... Tail> void dbg_out(Head H,Tail... T) {cerr<<H;if(sizeof...(Tail))cerr<<", ";dbg_out(T...);} #ifdef LOCAL #define dbg(...) cerr<<"["<<#__VA_ARGS__<<"] = [",dbg_out(__VA_ARGS__) #else #define dbg(...) #endif //---------------------------------mars4--------------------------------- class Fentree { ll logN; ll sum(ll i) { ll res=0; for(;i;i-=i&(-i)) res+=fentree[i]; return res; } public: ll N; vector<ll> fentree; void init(ll n) { N=n; logN=65-__builtin_clzll(n); fentree=vector<ll>(N+1); } void build(vector<ll> &a) { for(ll i=1;i<=N;i++) { fentree[i]+=a[i-1]; if(i+(i&-i)<=N) fentree[i+(i&-i)]+=fentree[i]; } } void update(ll i,ll val) { for(i++;i<=N;i+=i&(-i)) fentree[i]+=val; } ll sum(ll l,ll r) { if(l>r) { return 0; } return sum(r+1)-sum(l); } ll kth_element(ll k) { ll val=0; ll pos=0; for(ll i=logN;i>=0;i--) { ll r=1ll<<i; if(pos+r<=N and val+fentree[pos+r]<k) { val+=fentree[pos+r]; pos+=r; } } return pos; } }; const ll B=200; vector<pair<ll,ll>> a; vector<pair<ll,ll>> b; vector<ll> c; vector<ll> cnt; Fentree f; struct query { ll l,r,tot,id; bool operator < (const query &o) const { if(l/B==o.l/B) { if((l/B)%2==0) return r<o.r; else return r>o.r; } else return l<o.l; } }; class Mo { ll L=-1; ll R=-1; void updateL(ll i) { ll ind=a[i].ss; cnt[ind]++; if(cnt[ind]==2) { f.update(c[ind],1); } } void removeL(ll i) { ll ind=a[i].ss; if(cnt[ind]==2) { f.update(c[ind],-1); } cnt[ind]--; } void updateR(ll i) { ll ind=b[i].ss; cnt[ind]++; if(cnt[ind]==2) { f.update(c[ind],1); } } void removeR(ll i) { ll ind=b[i].ss; if(cnt[ind]==2) { f.update(c[ind],-1); } cnt[ind]--; } public: ll query(query q) { ll l=q.l; ll r=q.r; while(L<l) { L++; updateL(L); } while(R<r) { R++; updateR(R); } while(L>l) { removeL(L); L--; } while(R>r) { removeR(R); R--; } return f.sum(q.tot,f.N-1); } }; int main() { fastio(); ll z,n,m,t,k,i,j,l,d,h,r; cin>>n>>m; a=vector<pair<ll,ll>>(n); b=vector<pair<ll,ll>>(n); c=vector<ll>(n); cnt=vector<ll>(n); f.init(n); vector<ll> va; vector<ll> vb; vector<ll> vc; forn(i,0,n) { cin>>a[i].ff>>b[i].ff; c[i]=a[i].ff+b[i].ff; a[i].ss=i; b[i].ss=i; va.push_back(a[i].ff); vb.push_back(b[i].ff); vc.push_back(c[i]); } sort(all(va),greater<ll>()); sort(all(vb),greater<ll>()); sort(all(vc)); forn(i,0,n) { a[i].ff=lower_bound(all(va),a[i].ff,greater<ll>())-va.begin(); b[i].ff=lower_bound(all(vb),b[i].ff,greater<ll>())-vb.begin(); c[i]=lower_bound(all(vc),c[i])-vc.begin(); } sort(all(a)); sort(all(b)); vector<query> q(m); vector<ll> ans(m); forn(i,0,m) { auto &[l,r,tot,id]=q[i]; cin>>l>>r>>tot; l=upper_bound(all(va),l,greater<ll>())-va.begin()-1; r=upper_bound(all(vb),r,greater<ll>())-vb.begin()-1; tot=upper_bound(all(vc),tot)-vc.begin(); id=i; } sort(all(q)); Mo mo; for(auto qu:q) { ans[qu.id]=mo.query(qu); } for(ll i:ans) { cout<<i<<"\n"; } cerr<<"\nTime elapsed: "<<1000*clock()/CLOCKS_PER_SEC<<"ms\n"; return 0; }

Compilation message (stderr)

examination.cpp: In function 'int main()':
examination.cpp:212:5: warning: unused variable 'z' [-Wunused-variable]
  212 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |     ^
examination.cpp:212:11: warning: unused variable 't' [-Wunused-variable]
  212 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |           ^
examination.cpp:212:13: warning: unused variable 'k' [-Wunused-variable]
  212 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |             ^
examination.cpp:212:15: warning: unused variable 'i' [-Wunused-variable]
  212 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |               ^
examination.cpp:212:17: warning: unused variable 'j' [-Wunused-variable]
  212 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |                 ^
examination.cpp:212:19: warning: unused variable 'l' [-Wunused-variable]
  212 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |                   ^
examination.cpp:212:21: warning: unused variable 'd' [-Wunused-variable]
  212 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |                     ^
examination.cpp:212:23: warning: unused variable 'h' [-Wunused-variable]
  212 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |                       ^
examination.cpp:212:25: warning: unused variable 'r' [-Wunused-variable]
  212 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |                         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...