Submission #875206

#TimeUsernameProblemLanguageResultExecution timeMemory
875206abcvuitunggioSeats (IOI18_seats)C++17
100 / 100
1518 ms103388 KiB
#include "seats.h" #include <bits/stdc++.h> using namespace std; struct T{ int mn,cnt,sum; }st[4000001]; int n; vector <int> r,c; vector <vector <int>> a; T operator +(T a, T b){ T c; c.mn=min(a.mn,a.sum+b.mn); if (a.mn==a.sum+b.mn) c.cnt=a.cnt+b.cnt; else if (a.mn<a.sum+b.mn) c.cnt=a.cnt; else c.cnt=b.cnt; c.sum=a.sum+b.sum; return c; } int cell(int i, int j){ return (i<0||i>=a.size()||j<0||j>=a[0].size()?n:a[i][j]); } vector <int> best(int i, int j){ vector <int> v; for (int k=0;k<2;k++) for (int l=0;l<2;l++) v.push_back(cell(i+k,j+l)); sort(v.begin(),v.end()); return v; } int calc(int i){ int res=0; for (int j=0;j<2;j++) for (int k=0;k<2;k++){ auto v=best(r[i]-j,c[i]-k); res+=(i==v[0])-(i==v[1])+(i==v[2])-(i==v[3]); } return res; } void build(int node, int l, int r){ if (l==r){ st[node].mn=st[node].sum=calc(l); st[node].cnt=1; return; } int mid=(l+r)>>1; build(node<<1,l,mid); build(node<<1|1,mid+1,r); st[node]=st[node<<1]+st[node<<1|1]; } void update(int node, int l, int r, int i){ if (l>i||r<i||l>r) return; if (l==r){ st[node].mn=st[node].sum=calc(i); st[node].cnt=1; return; } int mid=(l+r)>>1; update(node<<1,l,mid,i); update(node<<1|1,mid+1,r,i); st[node]=st[node<<1]+st[node<<1|1]; } void give_initial_chart(int H, int W, vector <int> R, vector <int> C){ r=R; c=C; n=H*W; a.resize(H); for (int i=0;i<H;i++) a[i].assign(W,0); for (int i=0;i<n;i++) a[r[i]][c[i]]=i; build(1,0,n-1); } int swap_seats(int x, int y){ swap(r[x],r[y]); swap(c[x],c[y]); swap(a[r[x]][c[x]],a[r[y]][c[y]]); for (int i=-1;i<2;i++) for (int j=-1;j<2;j++){ update(1,0,n-1,cell(r[x]+i,c[x]+j)); update(1,0,n-1,cell(r[y]+i,c[y]+j)); } return st[1].cnt; }

Compilation message (stderr)

seats.cpp: In function 'int cell(int, int)':
seats.cpp:23:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     return (i<0||i>=a.size()||j<0||j>=a[0].size()?n:a[i][j]);
      |                  ~^~~~~~~~~~
seats.cpp:23:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     return (i<0||i>=a.size()||j<0||j>=a[0].size()?n:a[i][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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...