Submission #575160

# Submission time Handle Problem Language Result Execution time Memory
575160 2022-06-09T19:35:50 Z toloraia Reconstruction Project (JOI22_reconstruction) C++14
3 / 100
2828 ms 49044 KB
#include <bits/stdc++.h>
#define int long long
#define F first
#define S second
#define pb push_back
using namespace std;

const int N = 100005;

int n, m;
pair < int, pair < int, int > > P[N];

vector < int > g[505];

void del (int x, int y){
    for (int i = 0; i < g[x].size(); i++){
        if (g[x][i] == y){
            swap (g[x][i], g[x].back());
            g[x].pop_back();
            break;
        }
    }
}

int G[505][505];
int par[505];

void dfs (int k, int p){
    par[k] = p;
    for (int to : g[k])
        if (to != p)
            dfs (to, k);
}

int st[505], en[505];

int q;
int X[N*10], ans[N*10], C[N*10];

main() {
    //freopen ("in.in", "r", stdin);freopen ("out.out", "w", stdout);
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> m;
    for (int u,v,x,i = 1; i <= m; i++){
        cin >> u >> v >> x;
        P[i] = {x, {u, v}};
    }
    sort (P+1, P+m+1);
    for (int u,v,i = 1; i <= m; i++){
        u = P[i].S.F;
        v = P[i].S.S;
        dfs (u, 0);
        if (par[v] == 0){
            g[u].pb (v);
            g[v].pb (u);
            st[i] = 0;
            G[u][v] = G[v][u] = P[i].F;
        }
        else {
            int x = P[i].F+1;
            int node = v, c = 0;
            while (node != u){
                if (G[node][par[node]] < x){
                    x = G[node][par[node]];
                    c = node;
                }
                node = par[node];
            }
            del (c, par[c]);
            del (par[c], c);
            g[u].pb (v);
            g[v].pb (u);
            st[i] = (P[i].F + G[c][par[c]] + 2) / 2;
            G[u][v] = G[v][u] = P[i].F;
        }
        for (int j = 1; j <= n; j++)
            par[j] = 0;
    }
    for (int i = 1; i <= n; i++)
        g[i].clear();
    for (int u,v, i = m; i >= 1; i--){
        u = P[i].S.F;
        v = P[i].S.S;
        dfs (u, 0);
        if (par[v] == 0){
            g[u].pb (v);
            g[v].pb (u);
            en[i] = 1e9;
        }
        else {
            int x = P[i].F-1;
            int node = v, c = 0;
            while (node != u){
                if (G[node][par[node]] > x){
                    x = G[node][par[node]];
                    c = node;
                }
                node = par[node];
            }
            del (c, par[c]);
            del (par[c], c);
            g[u].pb (v);
            g[v].pb (u);
            en[i] = (P[i].F + G[c][par[c]]) / 2;
            G[u][v] = G[v][u] = P[i].F;
        }
        for (int j = 1; j <= n; j++)
            par[j] = 0;
    }
    cin >> q;
    for (int i = 1; i <= q; i++){
        cin >> X[i];
    }
    for (int i = 1; i <= m; i++){
        int a1, b1;
        int l = 1, r = q+1;
        while (l < r){
            int mid = l + r >> 1;
            if (X[mid] < st[i])
                l = mid + 1;
            else
                r = mid;
        }
        a1 = l;
        l = 0, r = q;
        while (l < r){
            int mid = l + r + 1 >> 1;
            if (X[mid] > P[i].F)
                r = mid - 1;
            else
                l = mid;
        }
        b1 = l;
        if (a1 <= b1){
        C[a1]--;
        C[b1+1]++;
        ans[a1] += P[i].F;
        ans[b1+1] -= P[i].F;
        }
        a1 = b1 + 1;

        l = 0, r = q;
        while (l < r){
            int mid = l + r + 1 >> 1;
            if (X[mid] > en[i])
                r = mid - 1;
            else
                l = mid;
        }
        b1 = l;
        if (a1 <= b1){
        C[a1]++;
        C[b1+1]--;
        ans[a1] -= P[i].F;
        ans[b1+1] += P[i].F;
        }
    }
    for (int i = 1; i <= q; i++){
        ans[i] += ans[i-1];
        C[i] += C[i-1];
        cout << abs(X[i] * C[i] + ans[i]) << endl;
    }
}

Compilation message

reconstruction.cpp: In function 'void del(long long int, long long int)':
reconstruction.cpp:16:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for (int i = 0; i < g[x].size(); i++){
      |                     ~~^~~~~~~~~~~~~
reconstruction.cpp: At global scope:
reconstruction.cpp:40:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   40 | main() {
      | ^~~~
reconstruction.cpp: In function 'int main()':
reconstruction.cpp:118:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  118 |             int mid = l + r >> 1;
      |                       ~~^~~
reconstruction.cpp:127:29: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  127 |             int mid = l + r + 1 >> 1;
      |                       ~~~~~~^~~
reconstruction.cpp:144:29: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  144 |             int mid = l + r + 1 >> 1;
      |                       ~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Incorrect 2088 ms 5616 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 2828 ms 49044 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Incorrect 1278 ms 42220 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Incorrect 2088 ms 5616 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Incorrect 2088 ms 5616 KB Output isn't correct
21 Halted 0 ms 0 KB -