답안 #799254

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
799254 2023-07-31T11:16:45 Z NeroZein The Potion of Great Power (CEOI20_potion) C++17
17 / 100
333 ms 44624 KB
#include "bits/stdc++.h"

using namespace std;

const int C = 50;
const int N = 1e5 + 5;
const int U = 2e5 + 5;
const int INF = 1e9; 

int h[N]; 

struct cmp {
  bool operator ()(int i, int j) const {
    return h[i] < h[j];
  }
};

void print (int u, set<int, cmp> se) {
  cout << "U: " << u << '\n';
  cout << "SE: ";
  for (int i : se) cout << i << ' ';
  cout << '\n';
}

int a[U], b[U];
set<int, cmp> cur[N]; 
vector<int> edits[N];
vector<set<int, cmp>> versions[N];


void edit (int v, set<int, cmp>& seU) {
  if (seU.count(v)) {
    seU.erase(v);
  } else {
    seU.insert(v);
  }
}

void init (int N_, int D, int H[]) {
  for (int i = 0; i < N_; ++i) {
    edits[i].push_back(0); 
    versions[i].push_back({});
    h[i] = H[i];
  }
}

void curseChanges (int U_, int A[], int B[]) {
  for (int day = 1; day <= U_; ++day) {
    a[day] = A[day - 1];
    b[day] = B[day - 1];
    edit(b[day], cur[a[day]]);
    edit(a[day], cur[b[day]]); 
    edits[a[day]].push_back(day);
    edits[b[day]].push_back(day);
    if (edits[a[day]].size() % C == 0) {
      versions[a[day]].push_back(cur[a[day]]);
    }
    if (edits[b[day]].size() % C == 0) {
      versions[b[day]].push_back(cur[a[day]]); 
    }
  }
}

int get (const set<int, cmp>& seU, const set<int, cmp>& seV) {
  vector<int> vecU, vecV;
  for (int i : seU) vecU.push_back(i);
  for (int i : seV) vecV.push_back(i);
  int pU = 0, pV = 0;
  int ret = INF;
  while (pU < (int) vecU.size() && pV < (int) vecV.size()) {
    if (h[vecU[pU]] < h[vecV[pV]]) {
      ret = min(ret, h[vecV[pV]] - h[vecU[pU]]);
      pU++;
    } else {
      ret = min(ret, h[vecU[pU]] - h[vecV[pV]]);
      pV++; 
    }
  }
  return ret;
}

int question (int x, int y, int v) {
  vector<set<int, cmp>> se(2); 
  for (int rep = 0; rep < 2; ++rep) {
    int last_edit = upper_bound(edits[x].begin(), edits[x].end(), v) - edits[x].begin() - 1;
    se[rep] = versions[x][last_edit / C];
    int st = last_edit - (last_edit % C) + 1;
    for (; st <= last_edit; ++st) {
      int i = a[edits[x][st]], j = b[edits[x][st]];
      if (i != x) {
        assert(j == x);
        swap(i, j);
      }
      edit(j, se[rep]); 
    }
    swap(x, y);
  }
  return get(se[0], se[1]); 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9936 KB Output is correct
2 Correct 5 ms 9936 KB Output is correct
3 Correct 5 ms 9936 KB Output is correct
4 Correct 25 ms 19924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 333 ms 44604 KB Output is correct
2 Correct 331 ms 44624 KB Output is correct
3 Incorrect 96 ms 28872 KB Incorrect
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 141 ms 30428 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 11856 KB Output is correct
2 Incorrect 10 ms 11088 KB Incorrect
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9704 KB Output is correct
2 Correct 5 ms 9936 KB Output is correct
3 Correct 5 ms 9936 KB Output is correct
4 Correct 5 ms 9936 KB Output is correct
5 Correct 25 ms 19924 KB Output is correct
6 Correct 333 ms 44604 KB Output is correct
7 Correct 331 ms 44624 KB Output is correct
8 Incorrect 96 ms 28872 KB Incorrect
9 Halted 0 ms 0 KB -