| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 516373 | Jomnoi | Pilot (NOI19_pilot) | C++17 | 746 ms | 80612 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define DEBUG 0
using namespace std;
const int N = 1e6 + 10;
const int MAX_H = 1e6;
vector <int> Q[N];
bool visited[N];
int parent[N];
int sz[N];
long long qs[N];
int root(int u) {
if(u == parent[u]) {
return u;
}
return parent[u] = root(parent[u]);
}
long long cal(int x) {
return 1ll * x * (x + 1) / 2;
}
int main() {
int n, q;
scanf(" %d %d", &n, &q);
for(int i = 1; i <= n; i++) {
parent[i] = i;
sz[i] = 1;
}
for(int i = 1; i <= n; i++) {
int h;
scanf(" %d", &h);
Q[h].push_back(i);
}
for(int h = 1; h <= MAX_H; h++) {
qs[h] = qs[h - 1];
for(auto i : Q[h]) {
visited[i] = true;
qs[h]++;
if(visited[i - 1] == true) {
int u = root(i), v = root(i - 1);
qs[h] -= cal(sz[u]) + cal(sz[v]);
if(sz[u] < sz[v]) {
swap(u, v);
}
sz[u] += sz[v];
parent[v] = u;
qs[h] += cal(sz[u]);
}
if(visited[i + 1] == true) {
int u = root(i), v = root(i + 1);
qs[h] -= cal(sz[u]) + cal(sz[v]);
if(sz[u] < sz[v]) {
swap(u, v);
}
sz[u] += sz[v];
parent[v] = u;
qs[h] += cal(sz[u]);
}
}
}
while(q--) {
int y;
scanf(" %d", &y);
printf("%lld\n", qs[y]);
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
