Submission #262770

# Submission time Handle Problem Language Result Execution time Memory
262770 2020-08-13T08:38:02 Z dantoh000 Colors (RMI18_colors) C++14
100 / 100
880 ms 99764 KB
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef pair<int,int> ii;
int n,m;
int A[150005];
int B[150005];
int U[200005];
int V[200005];
int has[150005];
vector<int> source[150005];
vector<int> sink[150005];
int ans = 0;
struct UFDS{
    vector<ii> op;
    int p[150005];
    int sz[150005];
    void init(int n){
        op.clear();
        for (int i = 1 ; i <= n; i++){
            p[i] = i;
            sz[i] = 1;
        }
    }
    int find(int x){
        return x == p[x] ? x : find(p[x]);
    }
    void un(int x, int y){
        x = find(x), y = find(y);
        if (x == y) return;
        if (sz[x] < sz[y]) swap(x,y);
        p[y] = x;
        sz[x] += sz[y];
        op.push_back({x,y});
    }
    void roll(int SZ){
        int x,y;
        while (op.size() > SZ){
            tie(x,y) = op.back(); op.pop_back();
            sz[x] -= sz[y];
            p[y] = y;
        }
    }
} ufds;
struct node{
    int s,e,m;
    vector<ii> V;
    node *l, *r;
    node (int _s, int _e): s(_s), e(_e){
        m = (s+e)/2;
        if (s != e){
            l = new node(s,m);
            r = new node(m+1,e);
        }
    }
    void up(int qs ,int qe, ii v){
        if (qs == s && qe == e){
            V.push_back(v);
            return;
        }
        if (qs > m) r->up(qs,qe,v);
        else if (qe<=m) l->up(qs,qe,v);
        else l->up(qs,m,v), r->up(m+1,qe,v);
    }
    void dfs(){
        int oldsz = ufds.op.size();
        for (auto x : V){
            ufds.un(x.fi,x.se);
        }
        if (s == e){
            for (auto x : source[s]){
                has[ufds.find(x)] = 1;
            }
            for (auto x : sink[s]){
                if (!has[ufds.find(x)]) ans = 0;
            }
            for (auto x : source[s]){
                has[ufds.find(x)] = 0;
            }
        }
        else{
            l->dfs();
            r->dfs();
        }
        ufds.roll(oldsz);
    }
} *root;
int main(){
    int TC;
    scanf("%d",&TC);
    while (TC--){
        ans = 1;
        scanf("%d%d",&n,&m);
        root = new node(1,n);
        ufds.init(n);
        for (int i = 1; i <= n; i++){
            source[i].clear();
            sink[i].clear();
        }
        for (int i = 1; i <= n; i++) {
            scanf("%d",&A[i]);
            source[A[i]].push_back(i);
        }
        for (int i = 1; i <= n; i++) {
            scanf("%d",&B[i]);
            sink[B[i]].push_back(i);
        }
        for (int i = 1; i <= m; i++) {
            scanf("%d%d",&U[i],&V[i]);
            int L = max(B[U[i]],B[V[i]]);
            int R = min(A[U[i]],A[V[i]]);
            if (L > R) continue;
            root->up(L,R,ii(U[i],V[i]));
        }
        root->dfs();
        printf("%d\n",ans);
    }

}

Compilation message

colors.cpp: In member function 'void UFDS::roll(int)':
colors.cpp:39:26: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   39 |         while (op.size() > SZ){
      |                ~~~~~~~~~~^~~~
colors.cpp: In function 'int main()':
colors.cpp:91:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   91 |     scanf("%d",&TC);
      |     ~~~~~^~~~~~~~~~
colors.cpp:94:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   94 |         scanf("%d%d",&n,&m);
      |         ~~~~~^~~~~~~~~~~~~~
colors.cpp:102:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  102 |             scanf("%d",&A[i]);
      |             ~~~~~^~~~~~~~~~~~
colors.cpp:106:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  106 |             scanf("%d",&B[i]);
      |             ~~~~~^~~~~~~~~~~~
colors.cpp:110:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  110 |             scanf("%d%d",&U[i],&V[i]);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 119 ms 29688 KB Output is correct
2 Correct 48 ms 15480 KB Output is correct
3 Correct 10 ms 8320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 15352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 130 ms 30200 KB Output is correct
2 Correct 50 ms 15608 KB Output is correct
3 Correct 11 ms 8448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 130 ms 30200 KB Output is correct
2 Correct 50 ms 15608 KB Output is correct
3 Correct 11 ms 8448 KB Output is correct
4 Correct 272 ms 55152 KB Output is correct
5 Correct 557 ms 78740 KB Output is correct
6 Correct 880 ms 99764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 119 ms 29688 KB Output is correct
2 Correct 48 ms 15480 KB Output is correct
3 Correct 10 ms 8320 KB Output is correct
4 Correct 130 ms 30200 KB Output is correct
5 Correct 50 ms 15608 KB Output is correct
6 Correct 11 ms 8448 KB Output is correct
7 Correct 125 ms 29976 KB Output is correct
8 Correct 50 ms 15480 KB Output is correct
9 Correct 11 ms 8576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 251 ms 54136 KB Output is correct
2 Correct 587 ms 78724 KB Output is correct
3 Correct 561 ms 75360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 12024 KB Output is correct
2 Correct 24 ms 9216 KB Output is correct
3 Correct 15 ms 8448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 119 ms 29688 KB Output is correct
2 Correct 48 ms 15480 KB Output is correct
3 Correct 10 ms 8320 KB Output is correct
4 Correct 104 ms 15352 KB Output is correct
5 Correct 130 ms 30200 KB Output is correct
6 Correct 50 ms 15608 KB Output is correct
7 Correct 11 ms 8448 KB Output is correct
8 Correct 272 ms 55152 KB Output is correct
9 Correct 557 ms 78740 KB Output is correct
10 Correct 880 ms 99764 KB Output is correct
11 Correct 125 ms 29976 KB Output is correct
12 Correct 50 ms 15480 KB Output is correct
13 Correct 11 ms 8576 KB Output is correct
14 Correct 251 ms 54136 KB Output is correct
15 Correct 587 ms 78724 KB Output is correct
16 Correct 561 ms 75360 KB Output is correct
17 Correct 54 ms 12024 KB Output is correct
18 Correct 24 ms 9216 KB Output is correct
19 Correct 15 ms 8448 KB Output is correct
20 Correct 146 ms 20020 KB Output is correct
21 Correct 545 ms 69844 KB Output is correct
22 Correct 792 ms 98856 KB Output is correct