제출 #1197067

#제출 시각아이디문제언어결과실행 시간메모리
1197067InvMOD스파이 (JOI13_spy)C++17
100 / 100
89 ms16656 KiB
#include<bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define eb emplace_back

#define vi vector<int>
#define pi pair<int,int>
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define compact(v) (v).erase(unique(all(v)), (v).end())

template<class T> using upq = priority_queue<T, vector<T>, greater<T>>;
template<class T> int lwrbound(const vector<T>& a, const T& b, const int s = 0){return int(lower_bound(s + all(a), b) - a.begin());}
template<class T> int uprbound(const vector<T>& a, const T& b, const int s = 0){return int(upper_bound(s + all(a), b) - a.begin());}

#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define ROF(i, a, b) for(int i = (a); i >= (b); i--)
#define sumof(x) accumulate(all(x), 0ll)
#define dbg(x) "[" << #x " = " << (x) << "]"
#define el "\n"

using ll = long long;
using ld = long double;

template<class T> bool ckmx(T& a, const T b){return (a < b ? a = b, true : false);}
template<class T> bool ckmn(T& a, const T b){return (a > b ? a = b, true : false);}

const int N = 2e5 + 5;
const int MOD = 1e9 + 7;
const ll INF = numeric_limits<ll>::max() / 8;



void Main()
{
    int n,m; cin >> n >> m;

    vi root(2, 0); vector<vi> adj[2];

    FOR(i, 0, 1) adj[i] = vector<vi>(n + 1, vi());

    FOR(i, 1, n){
        FOR(j, 0, 1){
            int p; cin >> p;

            if(!p){
                root[j] = i;
            }
            else{
                adj[j][p].push_back(i);
                //cout << p << " " << i << el;
            }
        }
    }

    int timerDFS; vector<vi> tin(2, vi(n + 1)), tout(2, vi(n + 1));

    function<void(int,int)> preDFS = [&](int x, int t) -> void{
        tin[t][x] = ++timerDFS;
        for(int v : adj[t][x]){
            preDFS(v, t);
        }
        tout[t][x] = timerDFS;
    };

    FOR(i, 0, 1) timerDFS = 0, preDFS(root[i], i);

    /*
        node x has tin[0][x], tin[1][x]

        it will success with some mission (u, v) that has
        +   tin[{0, 1}][u] <= tin[{0, 1}][x] && tin[{0, 1}][x] <= tout[{0, 1}][u]

        -> prefix sum (N <= 2000)
    */

    vector<vi> sum(n + 2, vi(n + 2, 0));

    auto upd = [&](int x1, int y1, int x2, int y2) -> void{
        sum[x1][y1]++;
        sum[x1][y2 + 1]--;
        sum[x2 + 1][y1]--;
        sum[x2 + 1][y2 + 1]++;
    };

    FOR(i, 1, m){
        int u,v; cin >> u >> v;

        upd(tin[0][u], tin[1][v], tout[0][u], tout[1][v]);
    }

    FOR(i, 1, n){
        FOR(j, 1, n){
            sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
        }
    }

    FOR(i, 1, n){
        cout << sum[tin[0][i]][tin[1][i]] << el;
    }
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    #define name "InvMOD"
    if(fopen(name".INP", "r")){
        freopen(name".INP", "r", stdin);
        freopen(name".OUT", "w", stdout);
    }

    int t = 1; while(t--) Main();
    return 0;
}

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

spy.cpp: In function 'int32_t main()':
spy.cpp:114:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  114 |         freopen(name".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
spy.cpp:115:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  115 |         freopen(name".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...