Submission #1287081

#TimeUsernameProblemLanguageResultExecution timeMemory
1287081Faisal_SaqibExamination (JOI19_examination)C++20
100 / 100
1325 ms507424 KiB
/* VENI VIDI VICI */ // #pragma GCC optimize("Ofast","unroll-all-loops","fast-math","no-stack-protector","give-no-fuck") #include <bits/stdc++.h> // #include <iostream> // #include <vector> // #include <algorithm> // #include <set> // #include <map> using namespace std; #define fi first #define se second #define pb push_back #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define rep(i,x, n) for (int i = (x); i < (n); ++i) #define repr(i,x, n) for (int i = (n) - 1; i >= (x); --i) mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); // #define sum accumulate //using i128 = __int128; using ll = long long; using ull = unsigned long long; using ld = long double; using str = string; using pi = pair<int, int>; using pl = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using vpi = vector<pair<int, int>>; using vvi = vector<vi>; using sll = set<ll>; template<class T> istream& operator>>(istream& is, vector<T>& v) { for(auto &i:v) is>>i; return is; } template<class T1,class T2> istream& operator>>(istream& is, pair<T1,T2>& p) { is>>p.fi>>p.se; return is; } template<class T> ostream& operator<<(ostream& os, const vector<T>& v) { for(const auto &i:v) os<<i<<' '; return os; } template<class T1,class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& p) { os<<p.fi<<' '<<p.se; return os; } void pyn(bool x) { cout<<(x?"YES":"NO")<<endl; } void pYN(bool x) { cout<<(x?"Yes":"No")<<endl; } void pAB(bool x) { cout<<(x?"Alice":"Bob")<<endl; } ll powmod(ll a,ll b,ll modulo) { if(b==0){ return 1; } ll temp=powmod(a,b/2,modulo); if(b%2==0){ return (temp*temp)%modulo; } else{ return (a*((temp*temp)%modulo))%modulo; } } bool Prime(ll n){ for (ll i = 2; i*i <= n; i++) if (n % i == 0) return false; return (n>1); } void readIO() { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // readIO(); int uwu=1; // cin>>uwu; for(int tc=1;tc<=uwu;tc++) { // cout<<"Case #"<<tc<<": "; solve(); } return 0; } const int N=2e5+100; int s[N],t[N],x[N],y[N],z[N],szy,ans[N]; struct SegmentTree { int cnt=0; int l,r; SegmentTree *nxt[2]={NULL,NULL}; SegmentTree(int s,int e) { l=s,r=e; nxt[0]=nxt[1]=NULL; } void Add(int&y) { if(r<l or r<y)return; cnt++; if(l==r)return; int m=(l+r)/2; bool cl=(y>m); if(nxt[cl]==NULL) { if(cl) nxt[cl]=new SegmentTree(m+1,r); else nxt[cl]=new SegmentTree(l,m); } nxt[cl]->Add(y); } int query(int&y) // >=y { // cout<<"Solving 1D "<<y<<' '<<l<<' '<<r<<endl; if(r<y)return 0; if(y<=l)return cnt; int ans=0; for(int i=0;i<2;i++) { if(nxt[i]!=NULL) { ans+=nxt[i]->query(y); } } return ans; } }; struct SegmentTree2D // dynamic sparse { SegmentTree *cnt=NULL; int l,r; SegmentTree2D *nxt[2]={NULL,NULL}; SegmentTree2D(int s,int e) { l=s,r=e; cnt=new SegmentTree(0,szy); nxt[0]=nxt[1]=NULL; } void Add(int& x,int& y) { if(x<l or r<x)return; cnt->Add(y); if(l==r)return; int m=(l+r)/2; bool cl=(x>m); if(nxt[cl]==NULL) { if(cl) nxt[cl]=new SegmentTree2D(m+1,r); else nxt[cl]=new SegmentTree2D(l,m); } nxt[cl]->Add(x,y); } int query(int& y,int& x) // >=y { // cout<<"Solving 2D "<<l<<' '<<r<<' '<<y<<' '<<x<<endl; if(r<y)return 0; if(y<=l) { // cout<<"SUOE"<<endl; return cnt->query(x); } int ans=0; for(int i=0;i<2;i++) { if(nxt[i]!=NULL) { ans+=nxt[i]->query(y,x); } } return ans; } }; SegmentTree *fen[N]; void Add(int x,int y) { x++; while(x>0) { if(fen[x]==NULL) { fen[x]=new SegmentTree(0,szy); } fen[x]->Add(y); x-=(x&-x); } } int query(int x,int y) { x++; int ans=0; while(x<N) { if(fen[x]!=NULL) { ans+=fen[x]->query(y); } x+=(x&-x); } return ans; } void solve() { ll n,q; cin>>n>>q; vector<vl> event; set<ll> curx,cury; for(int i=1;i<=n;i++) { cin>>s[i]>>t[i]; curx.insert(s[i]); cury.insert(t[i]); event.push_back({-s[i]-t[i],-1,i}); } for(int i=1;i<=q;i++) { cin>>x[i]>>y[i]>>z[i]; curx.insert(x[i]); cury.insert(y[i]); // cur.insert(z[i]); z[i]=max(z[i],x[i]+y[i]); event.push_back({-z[i],1,i}); } vl pressx(all(curx)); vl pressy(all(cury)); sort(all(event)); for(int i=1;i<=n;i++) { s[i]=lower_bound(all(pressx),s[i])-begin(pressx); t[i]=lower_bound(all(pressy),t[i])-begin(pressy); } for(int i=1;i<=q;i++) { x[i]=lower_bound(all(pressx),x[i])-begin(pressx); y[i]=lower_bound(all(pressy),y[i])-begin(pressy); } ll sz=pressx.size(); szy=pressy.size(); // SegmentTree2D *st=new SegmentTree2D(0,sz); // ds for(auto c:event) { if(c[1]==-1) { Add(s[c[2]],t[c[2]]); } else { ans[c[2]]=query(x[c[2]],y[c[2]]); } } for(int i=1;i<=q;i++) { cout<<ans[i]<<endl; } }

Compilation message (stderr)

examination.cpp: In function 'void readIO()':
examination.cpp:90:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |     freopen("input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:91:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |     freopen("output.txt", "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...