Submission #341214

#TimeUsernameProblemLanguageResultExecution timeMemory
341214beksultan04UFO (IZhO14_ufo)C++14
100 / 100
1116 ms91428 KiB
#include <bits/stdc++.h> using namespace std; //#define int long long #define pii pair<int,int> #define OK puts("OK"); #define NO puts("NO"); #define YES puts("YES"); #define fr first #define sc second #define ret return #define scanl(a) scanf("%lld",&a); #define scanll(a,b) scanf("%lld %lld",&a, &b); #define scanlll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c); #define scan1(a) scanf("%d",&a); #define scan2(a,b) scanf("%d %d",&a, &b); #define scan3(a,b,c) scanf("%d %d %d",&a,&b,&c); #define all(s) s.begin(),s.end() #define allr(s) s.rbegin(),s.rend() #define pb push_back #define sz(v) (int)v.size() #define endi puts(""); #define eps 1e-12 const int N = 1e6+12,INF=1e9+7; vector<int> decre; int r; struct segtree{ int sz; vector<int> t; void build(int n, vector<int> v){ assert((int)v.size() == n+1); sz=1; while(sz < n)sz<<=1; t.assign(sz*2, 0); for(int i=0;i<n;i++){ t[i+sz] = v[i+1]; }for(int i=sz-1;i>0;i--){ t[i] = max(t[i<<1], t[i<<1|1]); } } void decrease_it(int pos){ pos += sz-1; for(t[pos]--; pos > 1; pos >>= 1)t[pos>>1] = max(t[pos], t[pos^1]); } int remaining; int height; void going(int L, int R, int x){ if(remaining == 0 || t[x] < height)return; if(R-L == 1){ t[x]--; remaining--; decre.pb(x-sz+1); return; }int mid = (L+R)/2; going(L, mid, x<<1); going(mid, R, x<<1|1); t[x] = max(t[x<<1], t[x<<1|1]); } void going_in_reverse(int L, int R, int x){ if(remaining == 0 || t[x] < height)return; if(R-L == 1){ t[x]--; remaining--; decre.pb(x-sz+1); return; }int mid = (L+R)/2; going_in_reverse(mid, R, x<<1|1); going_in_reverse(L, mid, x<<1); t[x] = max(t[x<<1], t[x<<1|1]); } void decrease_them(int h){ decre.clear(); remaining = r; height = h; going(0, sz, 1); } void decrease_them_in_reverse(int h){ decre.clear(); remaining = r; height = h; going_in_reverse(0, sz, 1); } int get(int pos){ return t[pos+sz-1]; } }; main(){ int n,m,i,j,t,p,mx=0; vector <vector <int> > q; scan3(n,m,r) scan2(t,p) q.resize(n+1); vector <segtree> col(n+1); vector <segtree> row(m+1); for (i=0;i<=n;++i){ q[i].resize(m+1); for (j=0;j<=m;++j){ q[i][j]=0; } } for (i=1;i<=n;++i){ for (j=1;j<=m;++j){ scan1(q[i][j]) } col[i].build(m, q[i]); } for (i=1;i<=m;++i){ vector <int> pomosh(n+1); for (j=1;j<=n;++j)pomosh[j]=q[j][i]; row[i].build(n, pomosh); } while (t--){ char cha; int x,y; cin>>cha; scan2(x,y) if (cha == 'N'){ row[x].decrease_them(y); for (i=0;i<decre.size();++i){ col[decre[i]].decrease_it(x); } } if (cha == 'S'){ row[x].decrease_them_in_reverse(y); for (i=0;i<decre.size();++i){ col[decre[i]].decrease_it(x); } } if (cha == 'W'){ col[x].decrease_them(y); for (i=0;i<decre.size();++i){ row[decre[i]].decrease_it(x); } } if (cha == 'E'){ col[x].decrease_them_in_reverse(y); for (i=0;i<decre.size();++i){ row[decre[i]].decrease_it(x); } } } for (i=1;i<=n;++i){ for (j=1;j<=m;++j){ q[i][j] = col[i].get(j); } } for (i=1;i<=n;++i){ for (j=1;j<=m;++j){ q[i][j] = q[i-1][j]+q[i][j-1]-q[i-1][j-1]+q[i][j]; } } for (i=1;i<=n;++i){ for (j=1;j<=m;++j){ int ans=0,x=i,y=j; ans+=q[x][y]; ans+=q[max(x-p,0)][max(y-p,0)]; ans-=q[max(x-p,0)][y]; ans-=q[x][max(y-p,0)]; mx = max(ans,mx); } } cout <<mx; }

Compilation message (stderr)

ufo.cpp:87:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   87 | main(){
      |      ^
ufo.cpp: In function 'int main()':
ufo.cpp:127:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  127 |             for (i=0;i<decre.size();++i){
      |                      ~^~~~~~~~~~~~~
ufo.cpp:135:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  135 |             for (i=0;i<decre.size();++i){
      |                      ~^~~~~~~~~~~~~
ufo.cpp:143:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  143 |             for (i=0;i<decre.size();++i){
      |                      ~^~~~~~~~~~~~~
ufo.cpp:151:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  151 |             for (i=0;i<decre.size();++i){
      |                      ~^~~~~~~~~~~~~
ufo.cpp:16:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   16 | #define scan3(a,b,c) scanf("%d %d %d",&a,&b,&c);
      |                      ~~~~~^~~~~~~~~~~~~~~~~~~~~
ufo.cpp:90:5: note: in expansion of macro 'scan3'
   90 |     scan3(n,m,r)
      |     ^~~~~
ufo.cpp:15:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   15 | #define scan2(a,b) scanf("%d %d",&a, &b);
      |                    ~~~~~^~~~~~~~~~~~~~~~
ufo.cpp:91:5: note: in expansion of macro 'scan2'
   91 |     scan2(t,p)
      |     ^~~~~
ufo.cpp:14:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 | #define scan1(a) scanf("%d",&a);
      |                  ~~~~~^~~~~~~~~
ufo.cpp:104:13: note: in expansion of macro 'scan1'
  104 |             scan1(q[i][j])
      |             ^~~~~
ufo.cpp:15:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   15 | #define scan2(a,b) scanf("%d %d",&a, &b);
      |                    ~~~~~^~~~~~~~~~~~~~~~
ufo.cpp:123:9: note: in expansion of macro 'scan2'
  123 |         scan2(x,y)
      |         ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...