Submission #670002

#TimeUsernameProblemLanguageResultExecution timeMemory
670002dozerThe Potion of Great Power (CEOI20_potion)C++14
21 / 100
2815 ms27848 KiB
#include <bits/stdc++.h> using namespace std; #define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout) #define fastio() cin.tie(0), ios_base::sync_with_stdio(0) #define pb push_back #define sp " " //#define endl "\n" #define pii pair<int, int> #define st first #define nd second #define LOGN 18 #define C 500 vector<vector<int>> curr[100005]; vector<array<int, 3>> moves[10005]; int arr[100005], n; void init(int N, int D, int H[]) { n = N; for (int i = 0; i < N; i++) { vector<int> tmp; curr[i].pb(tmp); arr[i] = H[i]; } } void curseChanges(int U, int A[], int B[]) { set<int> flag[n + 5]; int cnt[n + 5]; for (int i = 0; i < U; i++) { int x = A[i], y= B[i]; cnt[x]++; cnt[y]++; if (flag[x].count(y)) flag[x].erase(y); else flag[x].insert(y); if (flag[y].count(x)) flag[y].erase(x); else flag[y].insert(x); if (cnt[x] == C) { vector<int> tmp(flag[x].begin(), flag[x].end()); curr[x].pb(tmp); cnt[x] = 0;; } if (cnt[y] == C) { vector<int> tmp(flag[y].begin(), flag[y].end()); curr[y].pb(tmp); cnt[y] = 0;; } moves[x].pb({y, i, (int)flag[x].count(y)}); moves[y].pb({x, i, (int)flag[y].count(x)}); } } int question(int x, int y, int v) { int a = 0, b = 0; if (moves[x].empty() || moves[y].empty()) return 1e9; for (int i = LOGN; i >= 0; i--) { int tmp1 = a + (1<<i), tmp2 = b + (1<<i); if (tmp1 < moves[x].size() && moves[x][tmp1][1] < v) a = tmp1; if (tmp2 < moves[y].size() && moves[y][tmp2][1] < v) b = tmp2; } if (moves[x][a][1] >= v || moves[y][b][1] >= v) return 1e9; set<int> aa, bb; for (auto i : curr[x][a / C]) aa.insert(i); for (auto i : curr[y][b / C]) bb.insert(i); int basea = (a / C) * C, baseb = (b / C) * C; for (int i = basea; i <= a; i++) { int curr = moves[x][i][0], flag = moves[x][i][2]; if (flag) aa.insert(curr); else aa.erase(curr); } for (int i = baseb; i <= b; i++) { int curr = moves[y][i][0], flag = moves[y][i][2]; if (flag) bb.insert(curr); else bb.erase(curr); } int i = 0, j = 0; int ans = 1e9; vector<int> k, l; for (auto i : aa) k.pb(arr[i]); for (auto i : bb) l.pb(arr[i]); sort(k.begin(), k.end()); sort(l.begin(), l.end()); while(i < k.size() && j < l.size()) { ans = min(ans, abs(k[i] - l[j])); if (k[i] < l[j]) i++; else j++; } return ans; }

Compilation message (stderr)

potion.cpp: In function 'int question(int, int, int)':
potion.cpp:68:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |         if (tmp1 < moves[x].size() && moves[x][tmp1][1] < v) a = tmp1;
      |             ~~~~~^~~~~~~~~~~~~~~~~
potion.cpp:69:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |         if (tmp2 < moves[y].size() && moves[y][tmp2][1] < v) b = tmp2;
      |             ~~~~~^~~~~~~~~~~~~~~~~
potion.cpp:99:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |     while(i < k.size() && j < l.size())
      |           ~~^~~~~~~~~~
potion.cpp:99:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |     while(i < k.size() && j < l.size())
      |                           ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...