답안 #121524

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
121524 2019-06-26T16:56:43 Z LittleFlowers__ 다리 (APIO19_bridges) C++14
0 / 100
3000 ms 14452 KB
#include <bits/stdc++.h>
using namespace std;
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define task "B"
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1<<(i-1)))

const int N=100010;

struct ed{
    int u,v,c,i;
}e[N];
struct qr{
    int o,u,x,i;
}q[N];
struct dt{
    int x,y,X,Y;
};
stack<dt> st;

int n,m,t;


int T=200,mode;
int id[N],b[N],ans[N];
vector<int> mm[N];

int root(int x){
    return id[x]<0?x:root(id[x]);
}
void join(int x,int y){
    if((x=root(x))==(y=root(y))) return;
    if(mode){
        st.push({x,y,id[x],id[y]});
    }
    if(id[x]>id[y]) swap(x,y);
    id[x]+=id[y];
    id[y]=x;
}
main(){
    //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);
    n=in;
    forinc(i,1,m=in) e[i]={in,in,in,i};
    forinc(i,1,t=in) q[i]={in,in,in,i};
    forinc(i,1,t){
        if(q[i].o==1) mm[q[i].u].pb(i);
        b[i]=(i-1)/T+1;
    }
    forinc(i,1,t){
        if(b[i]==b[i-1]) continue;
        vector<ed> E;
        vector<qr> Q;
        reset(id,-1);
        int j=i,l=i,r=b[i]*T > t ? t : b[i]*T;
        while(j<=t && b[j]==b[i]){
            if(q[j].o==2) Q.pb(q[j]);
            j++;
        }
        sort(all(Q),[](qr i,qr j){
            return i.x>j.x;
        });
        forinc(j,1,m){
            auto x=e[j];
            auto y=lower_bound(all(mm[x.i]),i);
            if(y==mm[x.i].end() || *y>r) E.pb(x);
        }
        sort(all(E),[](ed i,ed j){
            return i.c>j.c;
        });
        int k=0;
        forinc(j,0,Q.size()-1){
            while(k<E.size() && E[k].c>=Q[j].x){
                join(E[k].u,E[k].v);
                k++;
            }
            mode=1;
            forinc(k,l,r) if(q[k].o==1){
                auto y=lower_bound(all(mm[q[k].u]),l);
                if(y==mm[q[k].u].end() || *y>r) continue;
                y=lower_bound(all(mm[q[k].u]),Q[j].i);
                if(y==mm[q[k].u].begin() && e[q[*y].u].c>=Q[j].x){
                    join(e[q[*y].u].u,e[q[*y].u].v);
                    continue;
                }
                y--;
                if(k==*y && q[*y].x>=Q[j].x || *y<l && e[q[k].u].c>=Q[j].x){
                    join(e[q[*y].u].u,e[q[*y].u].v);
                }
            }
            mode=0;
            ans[Q[j].i]=-id[root(Q[j].u)];
            while(st.size()){
                auto x=st.top(); st.pop();
                id[x.x]=x.X;
                id[x.y]=x.Y;
            }
        }
    }
    forinc(i,1,t) if(q[i].o==2) cout<<ans[i]<<"\n";
}

Compilation message

bridges.cpp:54:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
bridges.cpp: In function 'int main()':
bridges.cpp:87:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             while(k<E.size() && E[k].c>=Q[j].x){
                   ~^~~~~~~~~
bridges.cpp:101:26: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
                 if(k==*y && q[*y].x>=Q[j].x || *y<l && e[q[k].u].c>=Q[j].x){
                    ~~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3072 KB Output is correct
2 Correct 4 ms 3072 KB Output is correct
3 Incorrect 24 ms 3456 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3097 ms 11904 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2247 ms 10480 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3025 ms 14452 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3097 ms 11904 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3072 KB Output is correct
2 Correct 4 ms 3072 KB Output is correct
3 Incorrect 24 ms 3456 KB Output isn't correct
4 Halted 0 ms 0 KB -