#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define semicolon ;
#define ryan bear
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18+7;
struct node
{
int l,r;
int d[200][200];
}tr[1500];
int r,c;
int opt[200][200];
inline void merge(int n,int l,int r)
{
node&m=tr[n];
node&x=tr[l];
node&y=tr[r];
for(int i=0;i<c;i++)
for(int j=0;j<c;j++)
opt[i][j]=-1;
for(int i=0;i<c;i++)
{
int j=0;
for(int k=0;k<c;k++)
{
int&o=opt[i][j]=0;
for(int k=0;++k<c;)
if(x.d[i][k]+y.d[k][j]<x.d[i][o]+y.d[o][j])
o=k;
}
}
for(int j=0;j<c;j++)
{
int i=c-1;
for(int k=0;k<c;k++)
{
int&o=opt[i][j]=0;
for(int k=0;++k<c;)
if(x.d[i][k]+y.d[k][j]<x.d[i][o]+y.d[o][j])
o=k;
}
}
for(int l=-c;++l<c;)
{
for(int i=0;i<c;i++)
{
int j=i+l;
if(j<0||j>=c||opt[i][j]!=-1)
continue;
int&o=opt[i][j]=opt[i][j-1];
for(int k=o;++k<=opt[i+1][j];)
if(x.d[i][k]+y.d[k][j]<x.d[i][o]+y.d[o][j])
o=k;
}
}
for(int i=0;i<c;i++)
for(int j=0;j<c;j++)
m.d[i][j]=x.d[i][opt[i][j]]+y.d[opt[i][j]][j];
return;
}
int dn;
vector<pi>adj[100010];
int d[100010];
inline void dijk(int s)
{
fill(d,d+dn,inf);
priority_queue<pi,vector<pi>,greater<pi> >pq;
pq.ep(d[s]=0,s);
while(!pq.empty())
{
int x=pq.top().se;
int cd=pq.top().fi;
pq.pop();
if(d[x]!=cd)
continue;
for(pi&t:adj[x])
if(d[t.fi]>cd+t.se)
pq.ep(d[t.fi]=cd+t.se,t.fi);
}
return;
}
vector<vector<int> >h,v;
inline void init(int n,int s,int e)
{
node&x=tr[n];
dn=(e-s+1)*c;
for(int i=0;i<dn;i++)
adj[i].clear();
for(int i=s;i<=e;i++)
{
for(int j=0;j<c-1;j++)
{
int cn=i*c-s*c+j;
adj[cn].eb(cn+1,h[i][j]);
adj[cn+1].eb(cn,h[i][j]);
}
}
for(int i=s;i<e;i++)
{
for(int j=0;j<c;j++)
{
int cn=i*c-s*c+j;
adj[cn].eb(cn+c,v[i][j]);
}
}
for(int i=0;i<c;i++)
{
dijk(i);
for(int j=0;j<c;j++)
x.d[i][j]=d[j+(e-s)*c];
}
return;
}
int tct=0,rt;
int init(int s,int e)
{
int cur=tct++;
node&x=tr[cur];
if(e-s<10)
{
x.l=x.r=0;
init(cur,s,e);
return cur;
}
int m=(s+e)/2;
x.l=init(s,m);
x.r=init(m,e);
merge(cur,x.l,x.r);
return cur;
}
void ch(int n,int s,int e,int r)
{
if(s>r||e<r)
return;
node&x=tr[n];
if(e-s<20)
{
init(n,s,e);
return;
}
int m=(s+e)/2;
ch(x.l,s,m,r);
ch(x.r,m,e,r);
merge(n,x.l,x.r);
return;
}
void cv(int n,int s,int e,int r)
{
if(s>r||e<=r)
return;
node&x=tr[n];
if(e-s<20)
{
init(n,s,e);
return;
}
int m=(s+e)/2;
cv(x.l,s,m,r);
cv(x.r,m,e,r);
merge(n,x.l,x.r);
return;
}
void init(int R,int C,int H[5000][200],int V[5000][200])
{
r=R;
c=C;
h.resize(r);
for(int i=0;i<r;i++)
for(int j=0;j<c-1;j++)
h[i].eb(H[i][j]);
v.resize(r-1);
for(int i=0;i<r-1;i++)
for(int j=0;j<c;j++)
v[i].eb(V[i][j]);
rt=init(0,r-1);
return;
}
void changeH(int P,int Q,int W)
{
h[P][Q]=W;
ch(rt,0,r-1,P);
return;
}
void changeV(int P,int Q,int W)
{
v[P][Q]=W;
cv(rt,0,r-1,P);
return;
}
int escape(int V1,int V2)
{
return tr[rt].d[V1][V2];
}
int H[5000][200];
int V[5000][200];
int main()
{
int R, C, E, P, Q, W, V1, V2, event, i, j;
int res;
FILE *f = stdin;
res = fscanf(f, "%d%d", &R, &C);
for (i = 0; i < R; ++i)
for (j = 0; j < C-1; ++j)
res = fscanf(f, "%d", &H[i][j]);
for (i = 0; i < R-1; ++i)
for (j = 0; j < C; ++j)
res = fscanf(f, "%d", &V[i][j]);
init(R, C, H, V);
res = fscanf(f, "%d", &E);
for (i = 0; i < E; i++) {
res = fscanf(f, "%d", &event);
if (event == 1) {
res = fscanf(f, "%d%d%d", &P, &Q, &W);
changeH(P, Q, W);
} else if (event == 2) {
res = fscanf(f, "%d%d%d", &P, &Q, &W);
changeV(P, Q, W);
} else if (event == 3) {
res = fscanf(f, "%d%d", &V1, &V2);
printf("%d\n", escape(V1, V2));
}
}
return 0;
}
Compilation message
grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
int res;
^~~
wombats.cpp: In function 'int main()':
wombats.cpp:211:9: warning: variable 'res' set but not used [-Wunused-but-set-variable]
int res;
^~~
/tmp/ccOEmZms.o: In function `main':
wombats.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccC6yJBv.o:grader.c:(.text.startup+0x0): first defined here
/tmp/ccC6yJBv.o: In function `main':
grader.c:(.text.startup+0x103): undefined reference to `init'
grader.c:(.text.startup+0x164): undefined reference to `escape'
grader.c:(.text.startup+0x1cf): undefined reference to `changeH'
grader.c:(.text.startup+0x23b): undefined reference to `changeV'
collect2: error: ld returned 1 exit status