답안 #166348

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
166348 2019-12-01T16:28:01 Z combi1k1 무지개나라 (APIO17_rainbow) C++14
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>

using namespace std;

#define X   first
#define Y   second

#define pb      emplace_back

#define sz(x)   (int)x.size()
#define all(x)  x.begin(),x.end()

const int   N   = 2e5 + 1;

typedef pair<int,int>   ii;
typedef vector<int>     vi;

vector<vi>  dx = {{0},{0,1},{0},{0,1}};
vector<vi>  dy = {{0},{0,1},{0,1},{0}};

struct  BIT2D   {
    vector<ii>  add;
    vector<int> v[N];
    void ini()  {
        sort(add.begin(),add.end());
        add.erase(unique(add.begin(),add.end()),add.end());
        for(ii  a : add)
        for(int x = a.X ; x < N ; x += x & -x)
            v[x].push_back(a.Y);
        for(int i = 1 ; i < N ; ++i)
            sort(v[i].begin(),v[i].end());
    }
    int get(int x,int l,int r)  {
        int ans = 0;
        for(; x > 0 ; x -= x & -x)  {
            auto L = lower_bound(v[x].begin(),v[x].end(),l);
            auto R = upper_bound(v[x].begin(),v[x].end(),r);

            ans += R - L;
        }
        return  ans;
    }
    int get(int l,int r,int u,int d)    {
        if (l > r)  return  0;
        if (u > d)  return  0;

        return  get(r,u,d) - get(l - 1,u,d);
    }
}   T[4];

int min_r =  1e9, min_c =  1e9;
int max_r = -1e9, max_c = -1e9;

void init(int R,int C,int sr,int sc,int m,string S) {
    S = "$" + S;

    ii  Head(sr,sc);

    for(char c : S) {
        if (c == 'N')   Head.X--;
        if (c == 'S')   Head.X++;
        if (c == 'W')   Head.Y--;
        if (c == 'E')   Head.Y++;

        min_r = min(min_r,Head.X);  max_r = max(max_r,Head.X);
        min_c = min(min_c,Head.Y);  max_c = max(max_c,Head.Y);

        for(int i = 0 ; i < 4 ; ++i)
        for(int x : dx[i])
        for(int y : dy[i])  T[i].add.pb(Head.X + x,Head.Y + y);
    }
    for(int i = 0 ; i < 4 ; ++i)    T[i].ini();
}
int colour(int l,int u,int r,int d) {
    int V = T[1].get(l + 1,r,u + 1,d);
    int F = T[0].get(l,r,u,d);
    int E = T[2].get(l,r,u + 1,d) + T[3].get(l + 1,r,u,d);

    return  E - V - F + 1 + (l < min_r && max_r < r && u < min_c && max_c < d);
}

Compilation message

/tmp/ccSZ1z8Z.o: In function `main':
grader.cpp:(.text.startup+0xcc): undefined reference to `init(int, int, int, int, int, char*)'
collect2: error: ld returned 1 exit status