# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
16322 |
2015-08-21T10:11:21 Z |
comet |
Ideal city (IOI12_city) |
C++ |
|
0 ms |
0 KB |
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef vector<int> vec;
typedef vector<vec> mat;
#define pb push_back
#define MOD 1000000000
struct pt{
int x,y,v;
pt(){}
pt(int x_,int y_):x(x_),y(y_){}
bool operator<(const pt& r)const{
return x!=r.x?x<r.x:y<r.y;
}
}s[100000];
mat path;
int n;
int cnt[100000];
ll dfs(int v,int p,ll &ans){
ll ret=0;
for(int i=0;i<path[v].size();i++){
int u=path[v][i];
if(u==p)continue;
ret+=dfs(u,v,ans);
}
ret+=cnt[v];
ans+=(n-ret)*ret;
ans%=MOD;
return ret;
}
int f(int N, int *X, int *Y) {
n=N;
for(int i=0;i<N;i++)s[i]=pt(X[i],Y[i]);
sort(s,s+N);
int sz=0;
for(int i=0;i<N;i++){
int p=i;
while(s[i].x==s[i+1].x)i++;
int v=p;
//printf("%d %d\n",p,i);
while(v<=i){
while(v<i&&s[v].y+1==s[v+1].y){
s[v].v=sz;
v++;
}
s[v].v=sz;
cnt[sz++]=s[v].y-s[p].y+1;
p=++v;
}
}
//puts("Umm...");
path.clear();
path.assign(sz,vec());
for(int i=0;i<N;i++){
auto it=lower_bound(s,s+N,pt(s[i].x-1,s[i].y));
if(it->x==s[i].x-1&&it->y==s[i].y)path[s[i].v].pb(it->v);
it=lower_bound(s,s+N,pt(s[i].x+1,s[i].y));
if(it->x==s[i].x+1&&it->y==s[i].y)path[s[i].v].pb(it->v);
}
for(int i=0;i<sz;i++){
//printf("%d : ",i);
sort(path[i].begin(),path[i].end());
path[i].erase(unique(path[i].begin(),path[i].end()),path[i].end());
//for(int j=0;j<path[i].size();j++)printf("%d ",path[i][j]);
//puts("");
}
//for(int i=0;i<sz;i++)printf("%d ",cnt[i]);
//puts("");
ll ret=0;
dfs(0,0,ret);
return (int)ret;
}
int DistanceSum(int N, int *X, int *Y){
return (f(N,X,Y)+f(N,Y,X))%MOD;
}
Compilation message
city.cpp: In function ‘ll dfs(int, int, ll&)’:
city.cpp:30:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<path[v].size();i++){
^
city.cpp: In function ‘int f(int, int*, int*)’:
city.cpp:67:3: warning: ‘auto’ changes meaning in C++11; please remove it [-Wc++0x-compat]
auto it=lower_bound(s,s+N,pt(s[i].x-1,s[i].y));
^
city.cpp:67:8: error: ‘it’ does not name a type
auto it=lower_bound(s,s+N,pt(s[i].x-1,s[i].y));
^
city.cpp:68:6: error: ‘it’ was not declared in this scope
if(it->x==s[i].x-1&&it->y==s[i].y)path[s[i].v].pb(it->v);
^
city.cpp:69:3: error: ‘it’ was not declared in this scope
it=lower_bound(s,s+N,pt(s[i].x+1,s[i].y));
^