# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
443107 | leaked | UFO (IZhO14_ufo) | C++14 | 1034 ms | 200476 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("-O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define vec vector
#define sz(x) ( int)x.size()
#define m_p make_pair
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
typedef long long ll;
typedef pair<ll, int> pli;
typedef pair<int,ll> pil;
typedef pair<int,int> pii;
typedef unsigned long long ull;
auto rng=bind(uniform_int_distribution<int>(1,1000),mt19937(time(0)));
template<class T> bool umax(T &a,const T &b){return (a<b?a=b,1:0);}
template<class T> bool umin(T &a,const T &b){return (a>b?a=b,1:0);}
const int N=1e5+1;
vec<int>vc;
int k;
struct tree{
vec<int>a;
vec<int>t;
void b_tr(int v,int tl,int tr){
if(tl==tr){
t[v]=a[tl];
return;
}
else{
int tm=(tl+tr)>>1;
b_tr(2*v,tl,tm);b_tr(2*v+1,tm+1,tr);
t[v]=max(t[2*v],t[2*v+1]);
}
}
void init(vec<int> b){
a=b;
t.resize(sz(a)*4);
b_tr(1,0,sz(a)-1);
}
void upd(int id,int x,int v,int tl,int tr){
if(tl==tr){
t[v]=x;
return;
}
int tm=(tl+tr)>>1;
if(tm>=id) upd(id,x,2*v,tl,tm);
else upd(id,x,2*v+1,tm+1,tr);
t[v]=max(t[2*v],t[2*v+1]);
}
void gol(int x,int v,int tl,int tr){
if(t[v]<x) return;
if(sz(vc)==k) return;
if(tl==tr){
vc.pb(tl);
return;
}
int tm=(tl+tr)>>1;
gol(x,2*v,tl,tm);gol(x,2*v+1,tm+1,tr);
}
void gor(int x,int v,int tl,int tr){
if(t[v]<x) return;
if(sz(vc)==k) return;
if(tl==tr){
vc.pb(tl);
return;
}
int tm=(tl+tr)>>1;
gor(x,2*v+1,tm+1,tr);
gor(x,2*v,tl,tm);
}
};
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n,m,q,p;
cin>>n>>m>>k>>q>>p;
vec<tree>r(n),c(m);
vec<vec<int>>a(n,vec<int>(m,0));
vec<vec<int>>b(m,vec<int>(n,0));
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>a[i][j];
b[j][i]=a[i][j];
}
}
for(int i=0;i<n;i++){
r[i].init(a[i]);
}
for(int i=0;i<m;i++){
c[i].init(b[i]);
}
auto change=[&](int i,int j,int x){
r[i].upd(j,x,1,0,m-1);
c[j].upd(i,x,1,0,n-1);
a[i][j]=x;
};
while(q--){
char ch;
int f,s;
cin>>ch>>f>>s;--f;
vc.clear();
if(ch=='N' || ch=='S'){
if(ch=='N')c[f].gol(s,1,0,n-1);
else c[f].gor(s,1,0,n-1);
for(auto &z : vc){
// cerr<<"THER "<<z<<endl;
change(z,f,a[z][f]-1);
}
}
else{
if(ch=='W')r[f].gol(s,1,0,m-1);
else r[f].gor(s,1,0,m-1);
for(auto &z : vc){
change(f,z,a[f][z]-1);
}
}
}
vec<vec<int>>pref(n,vec<int>(m,0));
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
pref[i][j]=(j?pref[i][j-1]:0)+a[i][j];
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
pref[i][j]=(i?pref[i-1][j]:0)+pref[i][j];
}
}
auto get=[&](int l1,int r1,int x1,int x2){
int sc=pref[r1][x2];
if(l1) sc-=pref[l1-1][x2];
if(x1) sc-=pref[r1][x1-1];
if(l1 && x1) sc+=pref[l1-1][x1-1];
return sc;
};
// cout<<"ALO"<<endl;
int ans=0;
for(int i=p-1;i<n;i++){
for(int j=p-1;j<m;j++){
// cout<<a[i][j]<<' ';
umax(ans,get(i-p+1,i,j-p+1,j));
}
// cout<<endl;
}
cout<<ans;
return 0;
}
/*
4 8 2 1 2
1 1 1 1 1 1 1 1
1 2 3 1 1 1 3 1
1 2 1 1 3 1 1 1
1 1 1 1 1 1 1 2
N 2 2
*/
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |