제출 #895513

#제출 시각아이디문제언어결과실행 시간메모리
895513AiperiiiTwo Currencies (JOI23_currencies)C++14
0 / 100
6 ms10844 KiB
#include <bits/stdc++.h> #define int long long #define all(x) x.begin(),x.end() #define ff first #define ss second #define pb push_back using namespace std; const int N=1e5+5; vector <int> c[N]; int ind_val[N]; pair <int,int> t[N*4]; void update(int v,int tl,int tr,int pos,int x){ if(tl==tr){ t[v].ff+=(ind_val[pos]*x); t[v].ss+=x; } else{ int tm=(tl+tr)/2; if(pos<=tm)update(v*2,tl,tm,pos,x); else update(v*2+1,tm+1,tr,pos,x); t[v].ff=t[v*2].ff+t[v*2+1].ff; t[v].ss=t[v*2].ss+t[v*2+1].ss; } } int NUM=0,SUM=0; void get(int v,int tl,int tr){ if(t[v].ff<=SUM){ SUM-=t[v].ff; NUM+=t[v].ss; } else if(tl==tr){ int x=SUM/ind_val[v]; SUM=0; NUM+=x; } else{ int tm=(tl+tr)/2; if(t[v*2].ff<=SUM){ get(v*2,tl,tm); get(v*2+1,tm+1,tr); } else{ get(v*2,tl,tm); } } } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n,m,q; cin>>n>>m>>q; for(int i=0;i<n-1;i++){ int a,b; cin>>a>>b; } set <int> st; for(int i=0;i<m;i++){ int x,y; cin>>x>>y; c[x].pb(y); st.insert(y); } int indx=1; map <int,int> val_ind; for(auto x : st){ ind_val[indx]=x; val_ind[x]=indx; indx++; } vector <vector <int> > v; vector <int> ans(q); for(int i=0;i<q;i++){ int l,r,x,y; cin>>l>>r>>x>>y; if(l>r)swap(l,r); v.pb({l,r,i,x,y}); } sort(all(v)); int k=sqrt(n); int cnt=1; vector < vector < vector <int> > > g; g.pb({}); for(int i=0;i<v.size();i++){ int newgr=0; while(v[i][0]>k*cnt){ cnt++; newgr=1; } if(newgr)g.pb({}); g[g.size()-1].pb(v[i]); } for(int i=0;i<g.size();i++){ if(g[i].size()==0)continue; for(int j=0;j<g[i].size();j++){ swap(g[i][j][0],g[i][j][1]); } sort(all(g[i])); int l=g[i][0][1]; int r=g[i][0][0]; int ind=g[i][0][2]; int x=g[i][0][3]; int y=g[i][0][4]; for(int k=l;k<r;k++){ for(auto d : c[k]){ update(1,1,st.size(),val_ind[d],1); } } NUM=0;SUM=y; get(1,1,st.size()); int left=t[1].ss-NUM; if(left>x)ans[ind]=-1; else ans[ind]=x-left; for(int j=1;j<g[i].size();j++){ l=g[i][j][1]; r=g[i][j][0]; ind=g[i][j][2]; x=g[i][j][3]; y=g[i][j][4]; for(int k=g[i][j-1][0];k<r;k++){ for(auto d : c[k]){ update(1,1,st.size(),val_ind[d],1); } } if(l<g[i][j-1][1]){ for(int k=l;k<g[i][j-1][1];k++){ for(auto d : c[k]){ update(1,1,st.size(),val_ind[d],1); } } } else if(l>g[i][j-1][1]){ for(int k=g[i][j-1][1];k<l;k++){ for(auto d : c[k]){ update(1,1,st.size(),val_ind[d],-1); } } } NUM=0;SUM=y; get(1,1,st.size()); int left=t[1].ss-NUM; if(left>x)ans[ind]=-1; else ans[ind]=x-left; } for(int j=1;j<=st.size()*4;j++){ t[j].ff=0;t[j].ss=0; } } for(int i=0;i<q;i++)cout<<ans[i]<<"\n"; }

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

currencies.cpp: In function 'int main()':
currencies.cpp:85:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |     for(int i=0;i<v.size();i++){
      |                 ~^~~~~~~~~
currencies.cpp:96:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<std::vector<long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |     for(int i=0;i<g.size();i++){
      |                 ~^~~~~~~~~
currencies.cpp:98:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |         for(int j=0;j<g[i].size();j++){
      |                     ~^~~~~~~~~~~~
currencies.cpp:120:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  120 |         for(int j=1;j<g[i].size();j++){
      |                     ~^~~~~~~~~~~~
currencies.cpp:155:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::set<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  155 |         for(int j=1;j<=st.size()*4;j++){
      |                     ~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...