답안 #211515

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
211515 2020-03-20T16:36:34 Z nicolaalexandra Traffickers (RMI18_traffickers) C++14
0 / 100
3500 ms 524292 KB
#include <bits/stdc++.h>
#define DIM 30010
using namespace std;
vector <int> L[DIM],w,aux;
int E[DIM*3],level[DIM],fth[DIM],first[DIM],p[DIM*3];
pair <int,int> rmq[20][DIM];
multiset <pair<int,int> > s[DIM];
int n,m,i,j,x,y,tip,q,k,t1,t2;
void dfs (int nod, int tata){
    E[++k] = nod;
    first[nod] = k;
    fth[nod] = tata;
    level[nod] = 1 + level[tata];
    for (auto vecin : L[nod]){
        if (vecin != tata){
            dfs (vecin,nod);
            E[++k] = nod;
        }}}

int get_lca (int x, int y){
    int posx = first[x], posy = first[y];
    if (posx > posy)
        swap (posx,posy);
    int nr = p[posy - posx + 1];
    pair <int, int> sol = min (rmq[nr][posx], rmq[nr][posy - (1<<nr) + 1]);
    return E[sol.second];
}
void drum (int x, int y){
    int lca = get_lca (x,y);

    w.clear();
    int nod = x;
    while (nod != lca){
        w.push_back(nod);
        nod = fth[nod];
    }
    w.push_back(lca);

    nod = y;
    aux.clear();
    while (nod != lca){
        aux.push_back(nod);
        nod = fth[nod];
    }
    for (j=aux.size()-1;j>=0;j--)
        w.push_back(aux[j]);
}
void adauga (int x, int y){

    drum (x,y);

    /// in w am lantul de la x la y

    int t = 1, lg = w.size();
    for (auto nod : w){

        /// il inserez pe t in setul nodului
        s[nod].insert(make_pair(t,lg));
        /*set <pair<int,int> > :: iterator it = s[nod].lower_bound(make_pair(t,0));
        if (it == s[nod].end() || it->first != t){
            s[nod].insert (make_pair(t,1));
        } else {
            /// inseamnca ca timpul t mai exista in set
            int cnt = it->second;
            s[nod].erase(it);
            s[nod].insert(make_pair(t,cnt+1));
        }*/

        t++;
    }
}
void scoate (int x, int y){
    drum (x,y);

    int t = 1, lg = w.size();

    for (auto nod : w){

        s[nod].erase (make_pair(t,lg));
        /*set <pair<int,int> > :: iterator it = s[nod].lower_bound (make_pair(t,0));
        /// stiu sigur ca am traficant
        int cnt = it->second;

        s[nod].erase(it);
        s[nod].insert(make_pair(t,cnt-1));
        */

        t++;
    }
}
int solve (int x, int y, int t){

    drum (x,y);
    int sol = 0;
    for (auto nod : w)
        for (auto it : s[nod]){
            int a = it.first, b = it.second;
            int nr = t / b;
            while (nr >= 0 && a + b * nr > t)
                nr--;
            sol += nr + 1;
        }

    return sol;
}
int main (){

   // ifstream cin ("traffickers.in");
    //ofstream cout ("traffickers.out");

    cin>>n;
    for (i=1;i<n;i++){
        cin>>x>>y;
        L[x].push_back(y);
        L[y].push_back(x);
    }
    dfs (1,0);

    for (i=1;i<=k;i++)
        rmq[0][i] = make_pair(level[E[i]],i);

    for (i=1;(1<<i)<=k;i++)
        for (j=1;j<=k;j++){
            rmq[i][j] = rmq[i-1][j];
            if (j + (1<<(i-1)) <= k && rmq[i-1][j + (1<<(i-1))].first < rmq[i][j].first)
                rmq[i][j] = rmq[i-1][j + (1<<(i-1))];
        }

    for (i=2;i<=k;i++)
        p[i] = p[i/2] + 1;

    cin>>m; /// nr inital de traficanti
    for (i=1;i<=m;i++){
        cin>>x>>y;
        adauga (x,y);
    }

    cin>>q;
    for (;q--;){
        cin>>tip>>x>>y;
        if (tip == 1){
            adauga (x,y);
            continue;
        }
        if (tip == 2){
            scoate (x,y);
            continue;
        }
        cin>>t1>>t2;
        cout<<solve(x,y,t2) - solve(x,y,t1-1)<<"\n";
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 2560 KB Output isn't correct
2 Incorrect 57 ms 3072 KB Output isn't correct
3 Incorrect 24 ms 3072 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2638 ms 8696 KB Output isn't correct
2 Incorrect 2324 ms 8336 KB Output isn't correct
3 Incorrect 2694 ms 9208 KB Output isn't correct
4 Incorrect 2534 ms 8824 KB Output isn't correct
5 Incorrect 2372 ms 8828 KB Output isn't correct
6 Incorrect 2468 ms 8776 KB Output isn't correct
7 Incorrect 2521 ms 8828 KB Output isn't correct
8 Incorrect 2714 ms 9012 KB Output isn't correct
9 Execution timed out 3569 ms 8824 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Runtime error 735 ms 524288 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Runtime error 740 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Runtime error 729 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Runtime error 750 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 728 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 733 ms 524288 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 731 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 731 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)