Submission #715023

#TimeUsernameProblemLanguageResultExecution timeMemory
715023Huseyn123Plahte (COCI17_plahte)C++17
0 / 160
144 ms12776 KiB
#include <bits/stdc++.h> #define MAX 20001 #define INF LLONG_MAX #define MOD 1000000007 #define mp make_pair #define mt make_tuple #define pb push_back #define ins insert #define ff first #define ss second #define gett(x,m) get<m>(x) #define all(a) a.begin(),a.end() #define lb(a,b) lower_bound(all(a),b) #define ub(a,b) upper_bound(all(a),b) #define sortv(a) sort(all(a)) #define sorta(a,sz) sort(a,a+sz) #define inputar(a,b){\ for(int i=0;i<b;i++){\ cin >> a[i];\ }\ } #define inputvec(a,b){\ for(int i=0;i<b;i++){\ ll num;\ cin >> num;\ a.pb(num);\ }\ } #define outputar(a,b){\ for(int i=0;i<b;i++){\ cout << a[i] << " ";\ }\ cout << "\n";\ } #define outputvec(a){\ for(auto x:a){\ cout << x << " ";\ }\ cout << "\n";\ } using namespace std; typedef long long ll; typedef unsigned long long ull; typedef tuple<ll,ll,ll> tll; typedef pair<ll,ll> pll; typedef double db; typedef long double ldb; inline void USACO(string filename){ freopen((filename+".in").c_str(),"r",stdin); freopen((filename+".out").c_str(),"w",stdout); } ll n,q,t=1,m,n2,m2,k,cnt=0,a[MAX],b[MAX],d2[MAX],x,y,z,x2,y2,z2,res1=0,cnt1,cnt2,cnt3; struct segtree2{ int size; vector<pll> tree; void init(int n){ size=1; while(size<n){ size*=2; } tree.assign(2*size,{-1,-1}); } void upd(int cnt,int l,int r,int v,int x,int lx,int rx){ if(lx>=r || rx<=l){ return; } if(lx>=l && rx<=r){ tree[x]=mp(v,cnt); return; } int m=(lx+rx)/2; upd(cnt,l,r,v,2*x+1,lx,m); upd(cnt,l,r,v,2*x+2,m,rx); } void upd(int cnt,int l,int r,int v){ upd(cnt,l,r,v,0,0,size); } pll get(int i,int x,int lx,int rx){ if(rx-lx==1){ return tree[x]; } int m=(lx+rx)/2; pll res; if(i<m){ res=get(i,2*x+1,lx,m); } else{ res=get(i,2*x+2,m,rx); } if(tree[x].ss>res.ss){ res=tree[x]; } return res; } ll get(int i){ return get(i,0,0,size).ff; } }; struct sheet{ ll x,y,x1,y1; }; struct ball{ ll x,y,z; }; vector<vector<ll>> g; sheet sheets[MAX]; ball balls[MAX]; set<ll> e[MAX]; void dfs(ll v){ b[v]=1; for(auto x:g[v]){ if(!b[x]){ dfs(x); } if(e[v].size()<e[x].size()){ swap(e[v],e[x]); } } for(auto x:g[v]){ for(auto y:e[x]){ e[v].ins(y); } } d2[v]=max(d2[v],(ll)e[v].size()); } void solve(){ cin >> n >> m; g.resize(n+1); for(int i=0;i<n;i++){ cin >> sheets[i].x >> sheets[i].y >> sheets[i].x1 >> sheets[i].y1; a[i]=-1; } for(int i=0;i<m;i++){ cin >> balls[i].x >> balls[i].y >> balls[i].z; } set<ll> c; map<ll,ll> d; for(int i=0;i<n;i++){ c.ins(sheets[i].x); c.ins(sheets[i].x1); } for(int i=0;i<m;i++){ c.ins(balls[i].x); } ll cnt1=0; for(auto x:c){ d[x]=cnt1; cnt1++; } for(int i=0;i<n;i++){ sheets[i].x=d[sheets[i].x]; sheets[i].x1=d[sheets[i].x1]; } for(int i=0;i<m;i++){ balls[i].x=d[balls[i].x]; } c.clear(); d.clear(); for(int i=0;i<n;i++){ c.ins(sheets[i].y); c.ins(sheets[i].y1); } for(int i=0;i<m;i++){ c.ins(balls[i].y); } ll cnt2=0; for(auto x:c){ d[x]=cnt2; cnt2++; } for(int i=0;i<n;i++){ sheets[i].y=d[sheets[i].y]; sheets[i].y1=d[sheets[i].y1]; } for(int i=0;i<m;i++){ balls[i].y=d[balls[i].y]; } c.clear(); d.clear(); vector<vector<pll>> start(cnt1); vector<vector<pll>> ended(cnt1); for(int i=0;i<n;i++){ start[sheets[i].x].pb(mp(0,i)); ended[sheets[i].x1].pb(mp(0,i)); } for(int i=0;i<m;i++){ start[balls[i].x].pb(mp(1,i)); } segtree2 st; st.init(cnt2); ll cnt=0; for(int i=0;i<cnt1;i++){ for(auto it:start[i]){ if(it.ff==0){ ll h=st.get(sheets[it.ss].y); if(h!=-1){ g[h].pb(it.ss); a[it.ss]=h; } st.upd(cnt,sheets[it.ss].y,sheets[it.ss].y1,it.ss); cnt++; } else{ ll h=st.get(it.ss); if(h!=-1){ e[h].ins(balls[it.ss].z); } } } for(auto it:ended[i]){ ll h=-1; st.upd(cnt,sheets[it.ss].y,sheets[it.ss].y1,a[it.ss]); cnt++; } } start.clear(); ended.clear(); start.shrink_to_fit(); ended.shrink_to_fit(); for(int i=0;i<n;i++){ if(b[i]==0){ dfs(i); } } for(int i=0;i<n;i++){ cout << d2[i] << "\n"; } } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); //USACO("poetry"); //freopen("input.txt","r",stdin); //cin >> t; ll cnt1=1; while(t--){ solve(); cnt1++; } } /* freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); ifstream fin("template.in"); ofstream fout("template.out"); */ /* freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); ifstream fin("template.in"); ofstream fout("template.out"); */ /* ll b[51][51]; b[0][0] = 1; for (int n = 1; n <= 50; ++n){ b[n][0] = b[n][n] = 1; for (int k = 1; k < n; ++k) b[n][k] = b[n - 1][k - 1] + b[n - 1][k]; } */

Compilation message (stderr)

plahte.cpp: In function 'void solve()':
plahte.cpp:211:16: warning: unused variable 'h' [-Wunused-variable]
  211 |             ll h=-1;
      |                ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...