제출 #597299

#제출 시각아이디문제언어결과실행 시간메모리
597299ThegeekKnight16Sum Zero (RMI20_sumzero)C++14
0 / 100
30 ms596 KiB
#include <bits/stdc++.h> using namespace std; struct inter { int begin, end; inter(int x, int y) {begin = x; end = y;} bool operator<(inter outro) { if (end == outro.end) return begin > outro.begin; return end < outro.end; } }; const int MAXN = 4e5 + 10; int v[MAXN]; vector<inter> Intervalos; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int N; cin >> N; for (int i = 1; i <= N; i++) {cin >> v[i]; v[i] += v[i-1];} for (int i = 1; i <= N; i++) { for (int j = i; j <= N; j++) { if (v[j] - v[i-1] == 0) Intervalos.emplace_back(i, j); } } sort(Intervalos.begin(), Intervalos.end()); vector<inter> Usados; int L = -1; for (inter atual : Intervalos) { if (atual.begin < L) continue; Usados.push_back(atual); } int Q; cin >> Q; for (int q = 1; q <= Q; q++) { int X, Y; cin >> X >> Y; int resp = 0; int Comec = -1; for (inter atual : Usados) { if (atual.begin < X || atual.begin < Comec) continue; if (atual.end > Y) break; resp++; Comec = atual.end; } cout << resp << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...