Submission #858011

#TimeUsernameProblemLanguageResultExecution timeMemory
858011sofijavelkovskaThe Potion of Great Power (CEOI20_potion)C++14
0 / 100
42 ms262144 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN=1e5, INF=1e9, ROOT=450; int n, d, u; vector<int> h, a, b; vector<int> adj[ROOT][MAXN]; void init(int N, int D, int H[]) { n=N; d=D; h.resize(n); for (int i=0; i<n; i++) h[i]=H[i]; return; } void curseChanges(int U, int A[], int B[]) { u=U; a.resize(u); b.resize(u); for (int i=0; i<u; i++) a[i]=A[i]; for (int i=0; i<=u; i++) b[i]=B[i]; set<int> currentadj[MAXN]; for (int i=0; i<u; i++) { if (i%ROOT==0) { for (int j=0; j<n; j++) { adj[i/ROOT][j].clear(); for (auto t : currentadj[j]) adj[i/ROOT][j].push_back(t); } } if (i==u) break; if (!currentadj[a[i]].count(b[i])) { currentadj[a[i]].insert(b[i]); currentadj[b[i]].insert(a[i]); } else { currentadj[a[i]].erase(b[i]); currentadj[b[i]].erase(a[i]); } } return; } int question(int x, int y, int v) { set<int> xtrust, ytrust; for (auto t : adj[v/ROOT][x]) xtrust.insert(t); for (auto t : adj[v/ROOT][y]) ytrust.insert(t); for (int i=v-v%ROOT; i<v; i++) { if (a[i]==x) { if (!xtrust.count(b[i])) xtrust.insert(b[i]); else xtrust.erase(b[i]); } if (b[i]==x) { if (!xtrust.count(a[i])) xtrust.insert(a[i]); else xtrust.erase(a[i]); } if (a[i]==y) { if (!ytrust.count(b[i])) ytrust.insert(b[i]); else ytrust.erase(b[i]); } if (b[i]==y) { if (!ytrust.count(a[i])) ytrust.insert(a[i]); else ytrust.erase(a[i]); } } vector<int> vx, vy; for (auto t : xtrust) vx.push_back(h[t]); for (auto t : ytrust) vy.push_back(h[t]); sort(vx.begin(), vx.end()); sort(vy.begin(), vy.end()); if (vx.empty() || vy.empty()) return INF; int mind=INF; int j=0; for (int i=0; i<vx.size(); i++) { while (j<vy.size() && vx[i]>vy[j]) j=j+1; if (j<vy.size()) mind=min(mind, vy[j]-vx[i]); if (j-1>=0) mind=min(mind, vx[i]-vy[j-1]); } return mind; }

Compilation message (stderr)

potion.cpp: In function 'int question(int, int, int)':
potion.cpp:109:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |     for (int i=0; i<vx.size(); i++)
      |                   ~^~~~~~~~~~
potion.cpp:111:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |         while (j<vy.size() && vx[i]>vy[j])
      |                ~^~~~~~~~~~
potion.cpp:113:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  113 |         if (j<vy.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...