QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#118129 | #6626. Real Mountains | hos_lyric# | 0 | 1ms | 3852kb | C++14 | 3.5kb | 2023-07-03 09:03:12 | 2024-05-31 18:48:24 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
vector<int> uf;
int root(int u) {
return (uf[u] < 0) ? u : (uf[u] = root(uf[u]));
}
bool connect(int u, int v) {
u = root(u);
v = root(v);
if (u == v) return false;
if (uf[u] > uf[v]) swap(u, v);
uf[u] += uf[v];
uf[v] = u;
return true;
}
constexpr int MO = 1'000'003;
constexpr Int INF = 1001001001001001001LL;
int N;
vector<Int> A;
int main() {
for (; ~scanf("%d", &N); ) {
A.assign(N + 2, INF);
for (int i = 1; i <= N; ++i) {
scanf("%lld", &A[i]);
}
vector<int> prv(N + 2, 0), nxt(N + 2, N + 1);
for (int i = 1; i <= N; ++i) {
int &j = prv[i] = i - 1;
for (; A[j] <= A[i]; j = prv[j]) {}
}
for (int i = N; i >= 1; --i) {
int &j = nxt[i] = i + 1;
for (; A[j] < A[i]; j = nxt[j]) {}
}
// cerr<<"prv = "<<prv<<endl;
// cerr<<"nxt = "<<nxt<<endl;
vector<Int> costs(N + 2, 0);
for (int i = 1; i <= N; ++i) if (1 <= prv[i] && nxt[i] <= N) {
const Int tar = min(A[prv[i]], A[nxt[i]]);
// cerr<<i<<" "<<A[i]<<" -> "<<tar<<endl;
costs[i] += tar * (tar - 1) / 2 - A[i] * (A[i] - 1) / 2;
{
vector<Int> bs;
for (int j = 1; j < i; ++j) if (A[j] > A[i]) {
bs.push_back(A[j]);
}
sort(bs.begin(), bs.end());
Int a = A[i];
for (const Int b : bs) {
const Int aa = min(b, tar);
costs[i] += (aa - a) * b;
a = aa;
}
}
{
vector<Int> bs;
for (int j = i + 1; j <= N; ++j) if (A[j] > A[i]) {
bs.push_back(A[j]);
}
sort(bs.begin(), bs.end());
Int a = A[i];
for (const Int b : bs) {
const Int aa = min(b, tar);
costs[i] += (aa - a) * b;
a = aa;
}
}
}
// cerr<<"costs = "<<costs<<endl;
vector<pair<int, int>> ps;
for (int i = 1; i <= N; ++i) if (1 <= prv[i] && nxt[i] <= N) {
ps.emplace_back(A[i], i);
}
sort(ps.begin(), ps.end());
// cerr<<"ps = "<<ps<<endl;
Int ans = 0;
uf.assign(N, -1);
for (const auto &p : ps) {
const int i = p.second;
const Int sz = -uf[i];
ans += (costs[i] % MO) * sz;
ans %= MO;
connect(i, (A[prv[i]] <= A[nxt[i]]) ? prv[i] : nxt[i]);
}
printf("%lld\n", ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 3
Accepted
time: 1ms
memory: 3852kb
input:
3 29 9 9
output:
0
result:
ok 1 number(s): "0"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
3 62 20 71
output:
7287
result:
ok 1 number(s): "7287"
Test #3:
score: -3
Wrong Answer
time: 0ms
memory: 3736kb
input:
10 72 33 22 22 13 49 53 57 72 85
output:
-40903
result:
wrong answer 1st numbers differ - expected: '40403', found: '-40903'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #2:
0%
Subtask #6:
score: 0
Skipped
Dependency #3:
0%
Subtask #7:
score: 0
Skipped
Dependency #1:
0%