Submission #858035

#TimeUsernameProblemLanguageResultExecution timeMemory
858035sofijavelkovskaThe Potion of Great Power (CEOI20_potion)C++14
31 / 100
3069 ms34272 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN=1e5, INF=1e9; int n, d, u; vector<int> h, a, b; vector<int> adj[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[n]; for (int i=0; i<u; i++) { 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]); } } for (int i=0; i<n; i++) { for (auto t : currentadj[i]) adj[i].push_back(h[t]); sort(adj[i].begin(), adj[i].end()); } return; } int question(int x, int y, int v) { vector<int> vx, vy; if (v==u) { vx=adj[x]; vy=adj[y]; } else { set<int> xtrust, ytrust; for (int i=0; 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]); } } 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:108:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |     for (int i=0; i<vx.size(); i++)
      |                   ~^~~~~~~~~~
potion.cpp:110:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |         while (j<vy.size() && vx[i]>vy[j])
      |                ~^~~~~~~~~~
potion.cpp:112:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  112 |         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...