Beams of Light
Problem LinkSolution by Mr.Olimpia — 100 pts
Code / Notes
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, l, q;
cin >> n >> l >> q;
vector<int> diff(n + 1, 0);
for (int j = 0; j < l; j++) {
int pos, alcance;
cin >> pos >> alcance;
pos--; // transformar para 0-indexado
int inicio = max(0, pos - alcance);
int fim = min(n - 1, pos + alcance);
diff[inicio]++;
diff[fim + 1]--;
}
// Soma prefixada
int quantidade = 0;
for (int i = 0; i < n; i++) {
quantidade += diff[i];
if (quantidade > 0) {
diff[i] = 1;
} else {
diff[i] = 0;
}
}
// Responder perguntas
for (int i = 0; i < q; i++) {
int x;
cin >> x;
x--;
if (diff[x]) {
cout << "Y\n";
} else {
cout << "N\n";
}
}
}
Last updated 1 month, 3 weeks ago