Submission #211933

# Submission time Handle Problem Language Result Execution time Memory
211933 2020-03-21T18:53:28 Z 3zp Making Friends on Joitter is Fun (JOI20_joitter2) C++14
100 / 100
1862 ms 123556 KB
#include<bits/stdc++.h>
#define ll long long
using namespace std;
map<ll,ll> f[300009];
map<ll,ll> g[300009];
ll p[300009],s[300009];
int br[309][309];
ll ans;
ll P(ll x){
    if(x == p[x]) return x;
    p[x] = P(p[x]);
    return p[x];
}
void un(ll x, ll y){
    x = P(x); y = P(y);
    if(x == y ) return;
    if(f[x].size() + g[x].size() >
       f[y].size() + g[y].size()) 
      swap(x, y);
    ans -= s[x] * (ll)f[x].size() - s[x];
    ans -= s[y] * (ll)f[y].size() - s[y];
    s[y] += s[x];
    p[x] = y;
    vector<int> v;
    for(auto it = f[x].begin(); it != f[x].end(); it++){
        f[y][it->first]=1;
        int u = P(it->first);
        if(g[y].find(u) != g[y].end()) 
          v.push_back(it->first);
        g[u][y] = 1;
        if(g[u].find(x) != g[u].end()) 
          g[u].erase(g[u].find(x));
    }
    for(auto it = g[x].begin(); it != g[x].end(); it++){
        g[y][it->first] = 1;
        if(g[it->first].find(y) != g[it->first].end()) 
          v.push_back(it->first);
    }
    ans += s[y] * (ll)f[y].size() - s[y];
    for(int u : v)
        un(y, u);
}
main(){
    ll n, q;
    cin >> n >> q;
    for(ll i = 1; i <= n; i++)
        s[i] = 1, p[i] = i, f[i][i] = 1;
    while(q--){
        ll a, b;
        cin >> a >> b;
        ll c = P(b), d = P(a);
        if(f[c].find(a) == f[c].end()){
            if(g[c].find(d) != g[c].end()) un(a, b);
            else{
                f[c][a] = 1,
                ans += s[c];
            }
            g[P(a)][c] = 1;
        }
        cout<<ans<<endl;
    }
}

Compilation message

joitter2.cpp:43:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
# Verdict Execution time Memory Grader output
1 Correct 21 ms 28544 KB Output is correct
2 Correct 19 ms 28544 KB Output is correct
3 Correct 18 ms 28544 KB Output is correct
4 Correct 19 ms 28544 KB Output is correct
5 Correct 19 ms 28544 KB Output is correct
6 Correct 19 ms 28416 KB Output is correct
7 Correct 24 ms 28544 KB Output is correct
8 Correct 30 ms 28544 KB Output is correct
9 Correct 30 ms 28544 KB Output is correct
10 Correct 25 ms 28800 KB Output is correct
11 Correct 20 ms 28544 KB Output is correct
12 Correct 19 ms 28544 KB Output is correct
13 Correct 19 ms 28544 KB Output is correct
14 Correct 19 ms 28544 KB Output is correct
15 Correct 20 ms 28544 KB Output is correct
16 Correct 19 ms 28544 KB Output is correct
17 Correct 24 ms 28544 KB Output is correct
18 Correct 22 ms 28544 KB Output is correct
19 Correct 19 ms 28544 KB Output is correct
20 Correct 20 ms 28544 KB Output is correct
21 Correct 28 ms 28544 KB Output is correct
22 Correct 21 ms 28544 KB Output is correct
23 Correct 22 ms 28544 KB Output is correct
24 Correct 20 ms 28544 KB Output is correct
25 Correct 33 ms 28544 KB Output is correct
26 Correct 20 ms 28544 KB Output is correct
27 Correct 19 ms 28544 KB Output is correct
28 Correct 20 ms 28544 KB Output is correct
29 Correct 19 ms 28544 KB Output is correct
30 Correct 20 ms 28544 KB Output is correct
31 Correct 26 ms 28544 KB Output is correct
32 Correct 19 ms 28544 KB Output is correct
33 Correct 27 ms 28672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 28544 KB Output is correct
2 Correct 19 ms 28544 KB Output is correct
3 Correct 18 ms 28544 KB Output is correct
4 Correct 19 ms 28544 KB Output is correct
5 Correct 19 ms 28544 KB Output is correct
6 Correct 19 ms 28416 KB Output is correct
7 Correct 24 ms 28544 KB Output is correct
8 Correct 30 ms 28544 KB Output is correct
9 Correct 30 ms 28544 KB Output is correct
10 Correct 25 ms 28800 KB Output is correct
11 Correct 20 ms 28544 KB Output is correct
12 Correct 19 ms 28544 KB Output is correct
13 Correct 19 ms 28544 KB Output is correct
14 Correct 19 ms 28544 KB Output is correct
15 Correct 20 ms 28544 KB Output is correct
16 Correct 19 ms 28544 KB Output is correct
17 Correct 24 ms 28544 KB Output is correct
18 Correct 22 ms 28544 KB Output is correct
19 Correct 19 ms 28544 KB Output is correct
20 Correct 20 ms 28544 KB Output is correct
21 Correct 28 ms 28544 KB Output is correct
22 Correct 21 ms 28544 KB Output is correct
23 Correct 22 ms 28544 KB Output is correct
24 Correct 20 ms 28544 KB Output is correct
25 Correct 33 ms 28544 KB Output is correct
26 Correct 20 ms 28544 KB Output is correct
27 Correct 19 ms 28544 KB Output is correct
28 Correct 20 ms 28544 KB Output is correct
29 Correct 19 ms 28544 KB Output is correct
30 Correct 20 ms 28544 KB Output is correct
31 Correct 26 ms 28544 KB Output is correct
32 Correct 19 ms 28544 KB Output is correct
33 Correct 27 ms 28672 KB Output is correct
34 Correct 43 ms 28672 KB Output is correct
35 Correct 852 ms 32248 KB Output is correct
36 Correct 901 ms 34936 KB Output is correct
37 Correct 897 ms 34936 KB Output is correct
38 Correct 902 ms 34528 KB Output is correct
39 Correct 33 ms 28920 KB Output is correct
40 Correct 44 ms 29712 KB Output is correct
41 Correct 40 ms 29696 KB Output is correct
42 Correct 32 ms 28920 KB Output is correct
43 Correct 33 ms 29056 KB Output is correct
44 Correct 33 ms 29048 KB Output is correct
45 Correct 33 ms 28928 KB Output is correct
46 Correct 32 ms 28928 KB Output is correct
47 Correct 35 ms 29436 KB Output is correct
48 Correct 35 ms 29440 KB Output is correct
49 Correct 56 ms 29944 KB Output is correct
50 Correct 916 ms 34872 KB Output is correct
51 Correct 51 ms 29304 KB Output is correct
52 Correct 874 ms 33416 KB Output is correct
53 Correct 55 ms 29816 KB Output is correct
54 Correct 890 ms 34040 KB Output is correct
55 Correct 35 ms 29312 KB Output is correct
56 Correct 38 ms 29304 KB Output is correct
57 Correct 35 ms 29688 KB Output is correct
58 Correct 34 ms 29688 KB Output is correct
59 Correct 36 ms 29824 KB Output is correct
60 Correct 844 ms 32504 KB Output is correct
61 Correct 37 ms 29304 KB Output is correct
62 Correct 912 ms 34244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 28544 KB Output is correct
2 Correct 19 ms 28544 KB Output is correct
3 Correct 18 ms 28544 KB Output is correct
4 Correct 19 ms 28544 KB Output is correct
5 Correct 19 ms 28544 KB Output is correct
6 Correct 19 ms 28416 KB Output is correct
7 Correct 24 ms 28544 KB Output is correct
8 Correct 30 ms 28544 KB Output is correct
9 Correct 30 ms 28544 KB Output is correct
10 Correct 25 ms 28800 KB Output is correct
11 Correct 20 ms 28544 KB Output is correct
12 Correct 19 ms 28544 KB Output is correct
13 Correct 19 ms 28544 KB Output is correct
14 Correct 19 ms 28544 KB Output is correct
15 Correct 20 ms 28544 KB Output is correct
16 Correct 19 ms 28544 KB Output is correct
17 Correct 24 ms 28544 KB Output is correct
18 Correct 22 ms 28544 KB Output is correct
19 Correct 19 ms 28544 KB Output is correct
20 Correct 20 ms 28544 KB Output is correct
21 Correct 28 ms 28544 KB Output is correct
22 Correct 21 ms 28544 KB Output is correct
23 Correct 22 ms 28544 KB Output is correct
24 Correct 20 ms 28544 KB Output is correct
25 Correct 33 ms 28544 KB Output is correct
26 Correct 20 ms 28544 KB Output is correct
27 Correct 19 ms 28544 KB Output is correct
28 Correct 20 ms 28544 KB Output is correct
29 Correct 19 ms 28544 KB Output is correct
30 Correct 20 ms 28544 KB Output is correct
31 Correct 26 ms 28544 KB Output is correct
32 Correct 19 ms 28544 KB Output is correct
33 Correct 27 ms 28672 KB Output is correct
34 Correct 43 ms 28672 KB Output is correct
35 Correct 852 ms 32248 KB Output is correct
36 Correct 901 ms 34936 KB Output is correct
37 Correct 897 ms 34936 KB Output is correct
38 Correct 902 ms 34528 KB Output is correct
39 Correct 33 ms 28920 KB Output is correct
40 Correct 44 ms 29712 KB Output is correct
41 Correct 40 ms 29696 KB Output is correct
42 Correct 32 ms 28920 KB Output is correct
43 Correct 33 ms 29056 KB Output is correct
44 Correct 33 ms 29048 KB Output is correct
45 Correct 33 ms 28928 KB Output is correct
46 Correct 32 ms 28928 KB Output is correct
47 Correct 35 ms 29436 KB Output is correct
48 Correct 35 ms 29440 KB Output is correct
49 Correct 56 ms 29944 KB Output is correct
50 Correct 916 ms 34872 KB Output is correct
51 Correct 51 ms 29304 KB Output is correct
52 Correct 874 ms 33416 KB Output is correct
53 Correct 55 ms 29816 KB Output is correct
54 Correct 890 ms 34040 KB Output is correct
55 Correct 35 ms 29312 KB Output is correct
56 Correct 38 ms 29304 KB Output is correct
57 Correct 35 ms 29688 KB Output is correct
58 Correct 34 ms 29688 KB Output is correct
59 Correct 36 ms 29824 KB Output is correct
60 Correct 844 ms 32504 KB Output is correct
61 Correct 37 ms 29304 KB Output is correct
62 Correct 912 ms 34244 KB Output is correct
63 Correct 1245 ms 75968 KB Output is correct
64 Correct 1229 ms 76172 KB Output is correct
65 Correct 1235 ms 76040 KB Output is correct
66 Correct 820 ms 51192 KB Output is correct
67 Correct 1180 ms 107648 KB Output is correct
68 Correct 806 ms 51192 KB Output is correct
69 Correct 1012 ms 54076 KB Output is correct
70 Correct 837 ms 51112 KB Output is correct
71 Correct 816 ms 51064 KB Output is correct
72 Correct 1124 ms 74884 KB Output is correct
73 Correct 1136 ms 78500 KB Output is correct
74 Correct 1862 ms 96908 KB Output is correct
75 Correct 1482 ms 59792 KB Output is correct
76 Correct 1616 ms 76920 KB Output is correct
77 Correct 1638 ms 77304 KB Output is correct
78 Correct 739 ms 55292 KB Output is correct
79 Correct 1427 ms 60620 KB Output is correct
80 Correct 699 ms 55288 KB Output is correct
81 Correct 1319 ms 60152 KB Output is correct
82 Correct 1232 ms 69088 KB Output is correct
83 Correct 1196 ms 69048 KB Output is correct
84 Correct 1182 ms 86272 KB Output is correct
85 Correct 1277 ms 86244 KB Output is correct
86 Correct 1224 ms 122392 KB Output is correct
87 Correct 1577 ms 123556 KB Output is correct
88 Correct 1204 ms 76780 KB Output is correct
89 Correct 1680 ms 74752 KB Output is correct