Submission #831487

#TimeUsernameProblemLanguageResultExecution timeMemory
831487tolbiSeats (IOI18_seats)C++17
0 / 100
4017 ms28948 KiB
#include <bits/stdc++.h> using namespace std; #include "seats.h" #define tol(bi) (1LL<<((int)(bi))) struct BIT{ BIT(){} vector<vector<int>> arr; void init(int n, int m){ arr.resize(n,vector<int>(m,0)); } void update(int x, int y, int val){ arr[x][y]=val; } int minq(int xl, int xr, int yl, int yr){ int rval = 23232323; //cout<<xl<<" "<<xr<<" "<<yl<<" "<<yr<<endl; //cout<<arr.size()<<" "<<arr[0].size()<<endl; for (int i = xl; i <= xr; i++){ for (int j = yl; j <= yr; j++){ rval=min(rval,arr[i][j]); } } return rval; } int maxq(int xl, int xr, int yl, int yr){ int rval = 0; //cout<<xl<<" "<<xr<<" "<<yl<<" "<<yr<<endl; //cout<<arr.size()<<" "<<arr[0].size()<<endl; for (int i = xl; i <= xr; i++){ for (int j = yl; j <= yr; j++){ rval=max(rval,arr[i][j]); } } return rval; } }; vector<int> R,C; BIT fenwik; int H,W; void give_initial_chart(int _H, int _W, std::vector<int> _R, std::vector<int> _C) { R=_R,C=_C; H=_H,W=_W; fenwik.init(H,W); for (int i = 0; i < R.size(); ++i) { fenwik.update(R[i],C[i],i); } } int swap_seats(int a, int b) { swap(R[a],R[b]); swap(C[a],C[b]); fenwik.update(R[a],C[a],a); fenwik.update(R[b],C[b],b); int n = R.size(); int crmax = 0; int ans = 1; int xl=R[0],xr=R[0]; int yl=C[0],yr=C[0]; while (crmax<R.size()-1){ int minel = 23232323; //cout<<crmax<<endl; //cout<<"ISTE GELDIK"<<endl; if (xl>0) minel=min(minel,fenwik.minq(0,xl-1,0,W-1)); //cout<<"GIDIYORUZ"<<endl; if (xr+1<H) minel=min(minel,fenwik.minq(xr+1,H-1,0,W-1)); //cout<<"BILINMEZ BIR"<<endl; if (yl>0) minel=min(minel,fenwik.minq(xl,xr,0,yl-1)); //cout<<"DIYARA"<<endl; if (yr+1<W) minel=min(minel,fenwik.minq(xl,xr,yr+1,W-1)); //cout<<"ESKIDEN KARPUR IDIK"<<endl; //cout<<xl<<" "<<xr<<" "<<yl<<" "<<yr<<endl; //cout<<crmax<<endl; //cout<<minel<<endl; xr=max(xr,R[minel]); xl=min(xl,R[minel]); yr=max(yr,C[minel]); yl=min(yl,C[minel]); crmax=fenwik.maxq(xl,xr,yl,yr); crmax=max(crmax,minel); if ((xr-xl+1)*(yr-yl+1)==crmax+1) ans++; } return ans; }

Compilation message (stderr)

seats.cpp: In function 'void give_initial_chart(int, int, std::vector<int>, std::vector<int>)':
seats.cpp:44:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |  for (int i = 0; i < R.size(); ++i)
      |                  ~~^~~~~~~~~~
seats.cpp: In function 'int swap_seats(int, int)':
seats.cpp:59:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |  while (crmax<R.size()-1){
      |         ~~~~~^~~~~~~~~~~
seats.cpp:54:6: warning: unused variable 'n' [-Wunused-variable]
   54 |  int n = R.size();
      |      ^
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...