답안 #655971

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
655971 2022-11-06T08:00:04 Z lunchbox1 The Potion of Great Power (CEOI20_potion) C++17
100 / 100
2134 ms 29392 KB
#include <bits/stdc++.h>
using namespace std;
 
const int N = 100000, B = 300;
 
int n, d, u, q, h[N];
vector<vector<tuple<int, int, int>>> ev[N];
vector<int> tt[N];
 
void init(int n_, int d_, int h_[]) {
 n = n_, d = d_;
 for (int i = 0; i < n; i++)
  h[i] = h_[i];
}
void curseChanges(int u_, int i_[], int j_[]) {
 u = u_;
 for (int k = 1; k <= u; k++) {
  int i = i_[k - 1], j = j_[k - 1];
  if (ev[i].size() == 0 || (int) ev[i].back().size() == B) {
   if (ev[i].size() == 0)
    ev[i].push_back({});
   else {
    sort(ev[i].back().begin(), ev[i].back().end());
    vector<pair<int, int>> v;
    for (auto [w, x, t] : ev[i].back())
     if (v.size() == 0 || v.back() != make_pair(w, x))
      v.push_back({w, x});
     else
      v.pop_back();
    ev[i].push_back({});
    for (auto [w, x] : v)
     ev[i].back().push_back(make_tuple(w, x, k - 1));
   }
   tt[i].push_back(k);
  }
  ev[i].back().push_back({h[j], j, k});
  if (ev[j].size() == 0 || (int) ev[j].back().size() == B) {
   if (ev[j].size() == 0)
    ev[j].push_back({});
   else {
    sort(ev[j].back().begin(), ev[j].back().end());
    vector<pair<int, int>> v;
    for (auto [w, x, t] : ev[j].back())
     if (v.size() == 0 || v.back() != make_pair(w, x))
      v.push_back({w, x});
     else
      v.pop_back();
    ev[j].push_back({});
    for (auto [w, x] : v)
     ev[j].back().push_back(make_tuple(w, x, k - 1));
   }
   tt[j].push_back(k);
  }
  ev[j].back().push_back({h[i], i, k});
 }
 for (int i = 0; i < n; i++)
  if (ev[i].size())
   sort(ev[i].back().begin(), ev[i].back().end());
}
int question(int i, int j, int k) {
 int p;
 if (tt[i].size() == 0 || tt[j].size() == 0 || tt[i][0] > k || tt[j][0] > k)
  return 1000000000;
 p = upper_bound(tt[i].begin(), tt[i].end(), k) - tt[i].begin() - 1;
 vector<pair<int, int>> wi;
 for (auto [w, x, t] : ev[i][p]) {
  if (t > k)
   continue;
  if (wi.size() == 0 || wi.back() != make_pair(w, x))
   wi.push_back({w, x});
  else
   wi.pop_back();
 }
 p = upper_bound(tt[j].begin(), tt[j].end(), k) - tt[j].begin() - 1;
 vector<pair<int, int>> wj;
 for (auto [w, x, t] : ev[j][p]) {
  if (t > k)
   continue;
  if (wj.size() == 0 || wj.back() != make_pair(w, x))
   wj.push_back({w, x});
  else
   wj.pop_back();
 }
 int ans = 1000000000;
 for (int l = 0, r = 0; l < (int) wi.size(); l++) {
  while (r < (int) wj.size() && wi[l].first > wj[r].first)
   ans = min(ans, wi[l].first - wj[r++].first);
  if (r < (int) wj.size())
   ans = min(ans, wj[r].first - wi[l].first);
 }
 return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5072 KB Output is correct
2 Correct 5 ms 5044 KB Output is correct
3 Correct 4 ms 5132 KB Output is correct
4 Correct 17 ms 5940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 252 ms 21340 KB Output is correct
2 Correct 224 ms 21356 KB Output is correct
3 Correct 252 ms 15744 KB Output is correct
4 Correct 508 ms 19304 KB Output is correct
5 Correct 167 ms 15612 KB Output is correct
6 Correct 1726 ms 24552 KB Output is correct
7 Correct 399 ms 20060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 220 ms 21308 KB Output is correct
2 Correct 1703 ms 17688 KB Output is correct
3 Correct 501 ms 29176 KB Output is correct
4 Correct 1151 ms 24464 KB Output is correct
5 Correct 237 ms 22432 KB Output is correct
6 Correct 1317 ms 24424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 6088 KB Output is correct
2 Correct 65 ms 5564 KB Output is correct
3 Correct 147 ms 5516 KB Output is correct
4 Correct 315 ms 6096 KB Output is correct
5 Correct 242 ms 6480 KB Output is correct
6 Correct 56 ms 5532 KB Output is correct
7 Correct 319 ms 5780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 4 ms 5072 KB Output is correct
3 Correct 5 ms 5044 KB Output is correct
4 Correct 4 ms 5132 KB Output is correct
5 Correct 17 ms 5940 KB Output is correct
6 Correct 252 ms 21340 KB Output is correct
7 Correct 224 ms 21356 KB Output is correct
8 Correct 252 ms 15744 KB Output is correct
9 Correct 508 ms 19304 KB Output is correct
10 Correct 167 ms 15612 KB Output is correct
11 Correct 1726 ms 24552 KB Output is correct
12 Correct 399 ms 20060 KB Output is correct
13 Correct 220 ms 21308 KB Output is correct
14 Correct 1703 ms 17688 KB Output is correct
15 Correct 501 ms 29176 KB Output is correct
16 Correct 1151 ms 24464 KB Output is correct
17 Correct 237 ms 22432 KB Output is correct
18 Correct 1317 ms 24424 KB Output is correct
19 Correct 33 ms 6088 KB Output is correct
20 Correct 65 ms 5564 KB Output is correct
21 Correct 147 ms 5516 KB Output is correct
22 Correct 315 ms 6096 KB Output is correct
23 Correct 242 ms 6480 KB Output is correct
24 Correct 56 ms 5532 KB Output is correct
25 Correct 319 ms 5780 KB Output is correct
26 Correct 368 ms 21908 KB Output is correct
27 Correct 509 ms 29392 KB Output is correct
28 Correct 604 ms 25420 KB Output is correct
29 Correct 469 ms 19480 KB Output is correct
30 Correct 1410 ms 24204 KB Output is correct
31 Correct 2134 ms 16788 KB Output is correct
32 Correct 1221 ms 24492 KB Output is correct