Submission #136550

# Submission time Handle Problem Language Result Execution time Memory
136550 2019-07-25T13:43:09 Z egorlifar Synchronization (JOI13_synchronization) C++17
Compilation error
0 ms 0 KB
/*
ЗАПУСКАЕМ
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░
 */
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
 
using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define left left224
#define right right224
#define next next224
#define rank rank224
#define prev prev224
#define y1 y1224
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define files(FILENAME) read(FILENAME), write(FILENAME)
#define pb push_back
#define mp make_pair
const string FILENAME = "input";
const int MAXN = 100228;


int n, m, q;
int a[MAXN], b[MAXN];
bool on[MAXN];
int ans[MAXN];
vector<pair<int, int> > g[MAXN];
vector<pair<int, int> > pos[MAXN];
map<pair<int, int>, int> who;
map<pair<int, int>, bool> was;
map<pair<int, int>, vector<int> > cnt;
pair<int, int> f[MAXN];
int last[MAXN];


void calc(int a, int b) {
    if (was[{a, b}]) {
        return;
    }
    int id = who[{a, b}];
    was[{a, b}] = true;
    if (pos[id].empty()) {
        return;
    }
    cnt[{a, b}].resize(sz(pos[id]));
    set<pair<int, pair<int, int> > > s;
    vector<int> fk(sz(pos[id]), 0);
    for (auto h: g[b]) {
        if (h.first != a) {
           // cout << b + 1 << ' ' << h.first + 1 << endl; 
            calc(b, h.first);
            int id1 = h.second;
            if (!pos[id1].empty()) {
                int it = 0;
                int last = 0;
                for (auto x: pos[id1]) {
                    int l = 0;
                    int r = sz(pos[id]) - 1;
                    while (l < r) {
                        int mid = (l + r) >> 1;
                        if (pos[id][mid].second >= x.first)  {
                            r = mid;
                        } else {
                            l = mid + 1;
                        }
                    }
                    if (l < sz(pos[id]) && pos[id][l].second >= x.first) {
                        fk[l] += cnt[{b, h.first}][it] - last;
                        assert(cnt[{b, h.first}][it] >= last);
                        last = cnt[{b, h.first}][it];
                    }
                    it++;
                }
            }
        }
    }
    int cntf = 1;
    for (int i = 0; i < sz(pos[id]); i++) { 
        cntf += fk[i];
        cnt[{a, b}][i] = cntf;
    }
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //read(FILENAME); 
    cin >> n >> m >> q;
    for (int i = 0; i < n - 1; i++) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
        g[a[i]].pb({b[i], i});
        g[b[i]].pb({a[i], i});
        who[{a[i], b[i]}] = i;
        who[{b[i], a[i]}] = i;
    }   
    for (int i = 0; i < m; i++) {
        int id;
        cin >> id;
        id--;
        if (on[id]) {
            on[id] = false;
            pos[id].pb({last[id], i - 1});
        } else {
            on[id] = true;
            last[id] = i;
        }
    }
    for (int i = 0; i < n - 1; i++) {
        if (on[i]) {
            pos[i].pb({last[i], m - 1});
        }
    }
    for (int i = 0; i < q; i++) {
        int c;
        cin >> c;
        c--;
        int res = 1;
        for (auto h: g[c]) {
            if (!pos[h.second].empty()) {
                calc(c, h.first);
                res += cnt[{c, h.first}].back();
            }
        }
        cout << res << '\n';
    }
    return 0;
}

Compilation message

synchronization.cpp:107:61: error: macro "assert" passed 2 arguments, but takes just 1
                         assert(cnt[{b, h.first}][it] >= last);
                                                             ^
synchronization.cpp: In function 'void calc(int, int)':
synchronization.cpp:107:25: error: 'assert' was not declared in this scope
                         assert(cnt[{b, h.first}][it] >= last);
                         ^~~~~~
synchronization.cpp:107:25: note: suggested alternative: '__assert'
                         assert(cnt[{b, h.first}][it] >= last);
                         ^~~~~~
                         __assert