# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
334135 | 2020-12-08T11:56:48 Z | aryan12 | Pilot (NOI19_pilot) | C++17 | 343 ms | 82924 KB |
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 10; vector<pair<long long, long long> > a(N); long long ans[N]; bool IsThere[N]; long long par[N], Rank[N]; long long curans = 0; long long Find(long long x) { if(x != par[x]) { par[x] = Find(par[x]); } return par[x]; } void Unite(long long a, long long b) { if(!IsThere[a] || !IsThere[b]) return; long long roota = Find(a), rootb = Find(b); curans -= Rank[roota] * (Rank[roota] + 1) / 2; curans -= Rank[rootb] * (Rank[rootb] + 1) / 2; if(Rank[roota] > Rank[rootb]) { Rank[roota] += Rank[rootb]; par[b] = a; curans += Rank[roota] * (Rank[roota] + 1) / 2; } else { Rank[rootb] += Rank[roota]; par[a] = b; curans += Rank[rootb] * (Rank[rootb] + 1) / 2; } } void Solve() { long long n, q; cin >> n >> q; for(long long i = 0; i < N; i++) { IsThere[i] = false; par[i] = i; Rank[i] = 1; } for(long long i = 1; i <= n; i++) { cin >> a[i].first; a[i].second = i; } sort(a.begin() + 1, a.begin() + 1 + n); long long curpos = 1; for(long long i = 1; i <= N; i++) { ans[i] = ans[i - 1]; while(curpos <= n && a[curpos].first == i) { IsThere[a[curpos].second] = true; curans++; Unite(a[curpos].second, a[curpos].second + 1); Unite(a[curpos].second, a[curpos].second - 1); curpos++; } ans[i] = curans; } for(long long i = 1; i <= q; i++) { long long x; cin >> x; cout << ans[x] << endl; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); Solve(); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 81 ms | 81772 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 81 ms | 81772 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 81 ms | 81772 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 81 ms | 81772 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 104 ms | 81772 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 343 ms | 82924 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 327 ms | 82668 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 81 ms | 81772 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 81 ms | 81772 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 81 ms | 81772 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |