Submission #910819

#TimeUsernameProblemLanguageResultExecution timeMemory
910819EvirirTeleporters (IOI08_teleporters)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> using namespace std; using i64 = long long; #define L(i,j,k) for(int i=(j);i<=(k);++i) #define R(i,j,k) for(int i=(j);i>=(k);--i) constexpr int _N = 2E6 + 5; struct node { int index, pos; }a[_N]; inline bool cmp(const node& A, const node& B) { return A.pos < B.pos; } int nxt[_N], N, M, sz[_N], vis[_N], cnt; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> N >> M; L(i, 1, N) { static int l, r; cin >> l >> r; a[i].index = i; a[i].pos = l; a[i + N].index = i + N; a[i + N].pos = r; } sort(a + 1, a + 2 * N + 1, cmp); L(i, 1, N * 2) { //cerr << a[i].index << ' '; if (a[i].index >= N + 1) { int x = a[i].index - N, y = a[i].index; a[i].index = y; a[i].pos = x; } else { int x = a[i].index, y = N + a[i].index; a[i].index = x; a[i].pos = y; } //cerr << a[i].left << ' ' << a[i].right << ' '; } //cerr << '\n'; a[0].pos = 0; L(i, 1, 2 * N) nxt[a[i - 1].pos] = a[i].index; nxt[a[2 * N].pos] = 0; function<void(int)> dfs = [&vis, &sz, &cnt, &nxt](int u) { if (vis[u]) return; vis[u] = true; sz[cnt]++; if (!vis[nxt[u]]) dfs(nxt[u]); }; memset(vis, 0, sizeof(vis)); memset(sz, 0, sizeof(sz)); L(i, 0, 2 * N) { if (!vis[i]) { cnt++; sz[cnt] = 0; dfs(i); } } //~ L(i, 0, 2 * N){ //~ cerr << i << " has neighbours : "; //~ for(auto & v : G[i]) cerr << v << ' '; //~ cerr << '\n'; //~ } sort(sz + 2, sz + cnt + 1, greater<int>()); int ans = sz[1] - 1; //~ cerr << "cycle: "; //~ for(auto & v: sz){ //~ cerr << v << ' '; //~ } //~ cerr << '\n'; L(i, 2, cnt) { if (M == 0) break; M--; ans += sz[i]; ans += 2; } if (M & 1) { ans++; M--; } ans += 2 * M; cout << ans << '\n'; }

Compilation message (stderr)

teleporters.cpp: In function 'int main()':
teleporters.cpp:47:33: warning: capture of variable 'vis' with non-automatic storage duration
   47 |     function<void(int)> dfs = [&vis, &sz, &cnt, &nxt](int u) {
      |                                 ^~~
teleporters.cpp:13:28: note: 'int vis [2000005]' declared here
   13 | int nxt[_N], N, M, sz[_N], vis[_N], cnt;
      |                            ^~~
teleporters.cpp:47:39: warning: capture of variable 'sz' with non-automatic storage duration
   47 |     function<void(int)> dfs = [&vis, &sz, &cnt, &nxt](int u) {
      |                                       ^~
teleporters.cpp:13:20: note: 'int sz [2000005]' declared here
   13 | int nxt[_N], N, M, sz[_N], vis[_N], cnt;
      |                    ^~
teleporters.cpp:47:44: warning: capture of variable 'cnt' with non-automatic storage duration
   47 |     function<void(int)> dfs = [&vis, &sz, &cnt, &nxt](int u) {
      |                                            ^~~
teleporters.cpp:13:37: note: 'int cnt' declared here
   13 | int nxt[_N], N, M, sz[_N], vis[_N], cnt;
      |                                     ^~~
teleporters.cpp:47:50: warning: capture of variable 'nxt' with non-automatic storage duration
   47 |     function<void(int)> dfs = [&vis, &sz, &cnt, &nxt](int u) {
      |                                                  ^~~
teleporters.cpp:13:5: note: 'int nxt [2000005]' declared here
   13 | int nxt[_N], N, M, sz[_N], vis[_N], cnt;
      |     ^~~
teleporters.cpp: In lambda function:
teleporters.cpp:51:27: error: 'dfs' is not captured
   51 |         if (!vis[nxt[u]]) dfs(nxt[u]);
      |                           ^~~
teleporters.cpp:47:53: note: the lambda has no capture-default
   47 |     function<void(int)> dfs = [&vis, &sz, &cnt, &nxt](int u) {
      |                                                     ^
teleporters.cpp:47:25: note: 'std::function<void(int)> dfs' declared here
   47 |     function<void(int)> dfs = [&vis, &sz, &cnt, &nxt](int u) {
      |                         ^~~