제출 #1215325

#제출 시각아이디문제언어결과실행 시간메모리
1215325segfault_ikuyo이상적인 도시 (IOI12_city)C++20
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define f first
#define s second
#define pb push_back

const int maxn=1e5+5;
const int mod=1e9;
int n,ans;
pii pt[maxn];
vector<int> adj[maxn];
int l[maxn],r[maxn],pos[maxn],cnt[maxn];
int siz[maxn];

bool cmp(pii a,pii b){
    return (a.f==b.f)?(a.s<b.s):(a.f<b.f);
}

void dfs(int x,int p){
    siz[x]=cnt[x];
    for(int i:adj[x]){
        if(i==p) continue;
        dfs(i,x);
        siz[x]+=siz[i];
    }
    ans+=(n-siz[x])*siz[x];
    ans%=mod;
}

void solve(){
    int idx=0;
    l[0]=r[0]=pt[0].s;
    pos[0]=pt[0].f;
    cnt[0]=1;

    for(int i=1;i<n;i++){
        if(pt[i].f==pt[i-1].f&&pt[i].s==pt[i-1].s+1) {
            r[idx]++;
            cnt[idx]++;
        }else{
            pos[++idx]=pt[i].f;
            l[idx]=r[idx]=pt[i].s;
            cnt[idx]=1;
        }
    }

    int low=0,high=0;
    while(high<=idx){
        if(pos[low]==pos[high]){
            high++;
            continue;
        }
        if(pos[low]!=pos[high]-1){
            low++;
            continue;
        }
        if(l[low]<=r[high]&&l[high]<=r[low]){
            adj[low].pb(high);
            adj[high].pb(low);
            if(pos[high+1]!=pos[high]) low++;
            else if(l[low]<=r[high+1]&&l[high+1]<=r[low]) high++;
            else low++;
        }else{
            if(r[low]<l[high]) low++;
            else if(r[high]<l[low]) high++;
        }
    }
    dfs(0,-1);
}

signed main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin>>n;
    for(int i=0;i<n;i++) cin>>pt[i].f>>pt[i].s;
    sort(pt,pt+n,cmp);
    solve();

    for(int i=0;i<n;i++) swap(pt[i].f,pt[i].s);
    for(int i=0;i<n;i++) adj[i].clear();
    sort(pt,pt+n,cmp);
    solve();
    cout<<ans;
}

컴파일 시 표준 에러 (stderr) 메시지

/usr/bin/ld: /tmp/ccmPwFBg.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccQk06eD.o:city.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccmPwFBg.o: in function `main':
grader.cpp:(.text.startup+0x104): undefined reference to `DistanceSum(int, int*, int*)'
collect2: error: ld returned 1 exit status