Submission #595514

#TimeUsernameProblemLanguageResultExecution timeMemory
595514ThegeekKnight16Event Hopping (BOI22_events)C++14
0 / 100
809 ms16160 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; int Inicio[MAXN], Fim[MAXN], Marc[MAXN]; vector<int> Indices; int dp[MAXN][25]; int prox[MAXN]; bool cmp(int a, int b) { if (Fim[a] == Fim[b]) return Inicio[a] < Inicio[b]; return Fim[a] > Fim[b]; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int N, Q; cin >> N >> Q; for (int i = 1; i <= N; i++) { cin >> Inicio[i] >> Fim[i]; Indices.push_back(i); } sort(Indices.begin(), Indices.end(), cmp); vector<int> Usados, naoUsados; int L = 1e9 + 10; int Encima = -1; for (auto id : Indices) { if (Inicio[id] >= L) {naoUsados.push_back(id); prox[id] = Encima;} else { Usados.push_back(id); L = Inicio[id]; Marc[id] = 1; Encima = id; } } int p = 0; for (int i = 0; i < Usados.size(); i++) { int id = Usados[i]; int pd = Usados[p]; while (p+1 < i && Fim[id] <= Inicio[Usados[p+1]]) pd = Usados[++p]; cerr << id << " " << pd << '\n'; if (Fim[id] < Inicio[pd] || Fim[id] > Fim[pd]) prox[id] = id; else prox[id] = pd; } for (int i = 1; i <= N; i++) {dp[i][0] = prox[i]; cerr << prox[i] << " ";} for (int k = 1; k <= 20; k++) { for (int i = 1; i <= N; i++) { dp[i][k] = dp[ dp[i][k-1] ][k-1]; } } for (int q = 1; q <= Q; q++) { int X, Y; cin >> X >> Y; int D = X; int resp = 0; for (int k = 20; k >= 0; k--) { int id = dp[D][k]; if (Fim[id] <= Fim[Y]) { D = id; resp += (1 << k); } } if (Fim[D] < Inicio[Y] || Fim[D] > Fim[Y]) cout << "impossible" << '\n'; else { cout << resp+1 << '\n'; } } }

Compilation message (stderr)

events.cpp: In function 'int main()':
events.cpp:43:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for (int i = 0; i < Usados.size(); i++)
      |                     ~~^~~~~~~~~~~~~~~
#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...