Submission #997762

# Submission time Handle Problem Language Result Execution time Memory
997762 2024-06-12T19:20:27 Z RaresFelix Fancy Fence (CEOI20_fancyfence) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

#define int ll 
using vi = vector<int>;
using ii = pair<int, int>;
using ll = long long;

const int MOD = 1e9 + 7;
const int inv2 = 5e8 + 4;

struct DSU {
    int re = 0;
    vi e, s;
    DSU(int n, const vi &S0) : e(n, -1), s(S0) {}

    int repr(int u) {
        while(e[u] >= 0) u = e[u];
        return u;
    }

    void join(int u, int v) {
        u = repr(u);
        v = repr(v);
        if(u == v) return;
        if(e[u] > e[v]) swap(u, v);
        e[u] += e[v];
        e[v] = u;
        re = (re - 1ll * s[u] * (s[u] + 1) % MOD * int(5e8 + 4) % MOD) % MOD;
        re = (re - 1ll * s[v] * (s[v] + 1) % MOD * int(5e8 + 4) % MOD) % MOD;
        s[u] += s[v];
        re = (re + 1ll * s[u] * (s[u] + 1) % MOD * int(5e8 + 4) % MOD) % MOD;

        re = (re + MOD) % MOD;
    }
};

signed main() {
    int n;
    cin >> n;
    vi W(n);
    vector<ii> H(n);
    for(int i = 0; i < n; ++i) {
        cin >> H[i].first;
        H[i].second = i;
    }
    for(int i = 0; i < n; ++i)
        cin >> W[i];
    DSU Sol(n, W);
    vi on(n, 0);
    sort(H.begin(), H.end());
    ll s = 0, ant = 0;
    ll re = 0, hant = 0;
    for(int i = 0; i < n; ++i) {
        int dr = i;
        do {
            s += 1ll * W[dr] * (W[dr] + 1) % MOD * inv2 % MOD;
            int p = H[dr].second;
            on[p] = 1;
            if(p && on[p - 1]) Sol.join(p, p - 1);
            if(p + 1 < n && on[p + 1]) Sol.join(p, p + 1);
            ++dr;
        } while(dr < n && H[dr].first == H[dr - 1].first);
        ll cur = (s + Sol.re) % MOD * H[i].first % MOD;
        cur = (cur % MOD + MOD) % MOD;

        ll delta = cur - ant;
        delta = (delta % MOD + MOD) % MOD;

        ant = cur;

        re = (re + delta % MOD) % MOD;
        i = dr - 1;
    }
    cout << re << "\n";
    return 0;
}

Compilation message

fancyfence.cpp:5:13: error: 'll' was not declared in this scope
    5 | #define int ll
      |             ^~
fancyfence.cpp:6:19: note: in expansion of macro 'int'
    6 | using vi = vector<int>;
      |                   ^~~
fancyfence.cpp:6:22: error: template argument 1 is invalid
    6 | using vi = vector<int>;
      |                      ^
fancyfence.cpp:6:22: error: template argument 2 is invalid
fancyfence.cpp:5:13: error: 'll' was not declared in this scope
    5 | #define int ll
      |             ^~
fancyfence.cpp:7:17: note: in expansion of macro 'int'
    7 | using ii = pair<int, int>;
      |                 ^~~
fancyfence.cpp:5:13: error: 'll' was not declared in this scope
    5 | #define int ll
      |             ^~
fancyfence.cpp:7:22: note: in expansion of macro 'int'
    7 | using ii = pair<int, int>;
      |                      ^~~
fancyfence.cpp:7:25: error: template argument 1 is invalid
    7 | using ii = pair<int, int>;
      |                         ^
fancyfence.cpp:7:25: error: template argument 2 is invalid
fancyfence.cpp:15:5: error: 'vi' does not name a type
   15 |     vi e, s;
      |     ^~
fancyfence.cpp:16:22: error: 'vi' does not name a type
   16 |     DSU(int n, const vi &S0) : e(n, -1), s(S0) {}
      |                      ^~
fancyfence.cpp: In constructor 'DSU::DSU(ll, const int&)':
fancyfence.cpp:16:32: error: class 'DSU' does not have any field named 'e'
   16 |     DSU(int n, const vi &S0) : e(n, -1), s(S0) {}
      |                                ^
fancyfence.cpp:16:42: error: class 'DSU' does not have any field named 's'
   16 |     DSU(int n, const vi &S0) : e(n, -1), s(S0) {}
      |                                          ^
fancyfence.cpp: In member function 'll DSU::repr(ll)':
fancyfence.cpp:19:15: error: 'e' was not declared in this scope; did you mean 're'?
   19 |         while(e[u] >= 0) u = e[u];
      |               ^
      |               re
fancyfence.cpp: In member function 'void DSU::join(ll, ll)':
fancyfence.cpp:27:12: error: 'e' was not declared in this scope; did you mean 're'?
   27 |         if(e[u] > e[v]) swap(u, v);
      |            ^
      |            re
fancyfence.cpp:28:9: error: 'e' was not declared in this scope; did you mean 're'?
   28 |         e[u] += e[v];
      |         ^
      |         re
fancyfence.cpp:30:26: error: 's' was not declared in this scope
   30 |         re = (re - 1ll * s[u] * (s[u] + 1) % MOD * int(5e8 + 4) % MOD) % MOD;
      |                          ^
fancyfence.cpp: In function 'int main()':
fancyfence.cpp:42:5: error: 'vi' was not declared in this scope
   42 |     vi W(n);
      |     ^~
fancyfence.cpp:43:12: error: 'ii' was not declared in this scope
   43 |     vector<ii> H(n);
      |            ^~
fancyfence.cpp:43:14: error: template argument 1 is invalid
   43 |     vector<ii> H(n);
      |              ^
fancyfence.cpp:43:14: error: template argument 2 is invalid
fancyfence.cpp:45:17: error: invalid types 'int[ll {aka long long int}]' for array subscript
   45 |         cin >> H[i].first;
      |                 ^
fancyfence.cpp:46:10: error: invalid types 'int[ll {aka long long int}]' for array subscript
   46 |         H[i].second = i;
      |          ^
fancyfence.cpp:49:16: error: 'W' was not declared in this scope
   49 |         cin >> W[i];
      |                ^
fancyfence.cpp:50:16: error: 'W' was not declared in this scope
   50 |     DSU Sol(n, W);
      |                ^
fancyfence.cpp:51:7: error: expected ';' before 'on'
   51 |     vi on(n, 0);
      |       ^~~
      |       ;
fancyfence.cpp:52:12: error: request for member 'begin' in 'H', which is of non-class type 'int'
   52 |     sort(H.begin(), H.end());
      |            ^~~~~
fancyfence.cpp:52:23: error: request for member 'end' in 'H', which is of non-class type 'int'
   52 |     sort(H.begin(), H.end());
      |                       ^~~
fancyfence.cpp:59:22: error: invalid types 'int[ll {aka long long int}]' for array subscript
   59 |             int p = H[dr].second;
      |                      ^
fancyfence.cpp:60:13: error: 'on' was not declared in this scope; did you mean 'n'?
   60 |             on[p] = 1;
      |             ^~
      |             n
fancyfence.cpp:64:28: error: invalid types 'int[ll {aka long long int}]' for array subscript
   64 |         } while(dr < n && H[dr].first == H[dr - 1].first);
      |                            ^
fancyfence.cpp:64:43: error: invalid types 'int[ll {aka long long int}]' for array subscript
   64 |         } while(dr < n && H[dr].first == H[dr - 1].first);
      |                                           ^
fancyfence.cpp:65:40: error: invalid types 'int[ll {aka long long int}]' for array subscript
   65 |         ll cur = (s + Sol.re) % MOD * H[i].first % MOD;
      |                                        ^
fancyfence.cpp:54:16: warning: unused variable 'hant' [-Wunused-variable]
   54 |     ll re = 0, hant = 0;
      |                ^~~~