QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#117255 | #6626. Real Mountains | somethingnew# | 3 | 2ms | 4232kb | C++23 | 3.7kb | 2023-06-30 19:24:57 | 2024-05-31 18:43:40 |
Judging History
answer
// ↘ ⬇ ⬇ ⬇ ⬇ ⬇ ↙
// ➡ @roadfromroi ⬅
// ↗ ⬆ ⬆ ⬆ ⬆ ⬆ ↖
#include <iostream>
#include "vector"
#include "algorithm"
#include "numeric"
#include "climits"
#include "iomanip"
#include "bitset"
#include "cmath"
#include "map"
#include "deque"
#include "array"
#include "set"
#define all(x) x.begin(), x.end()
using namespace std;
#define int long long
int mod = 1e6 + 3;
struct segtree {
int sz;
vector<int> tree;
void make(vector<int> a) {
sz = 1;
while (sz < a.size())
sz *= 2;
tree.assign(sz * 2, {});
for (int i = 0; i < a.size(); ++i) {
tree[i + sz] = a[i];
}
for (int i = sz-1; i > 0; --i) {
tree[i] = min(tree[i * 2], tree[i * 2 + 1]);
}
}
void ch(int v) {
v += sz;
tree[v] = 1e15;
while (v != 1) {
v /= 2;
tree[v] = min(tree[v * 2], tree[v * 2 + 1]);
}
}
int get(int l, int r) {
//cerr << l << ' ' << r << ' ' << sz << endl;
l += sz;
r += sz;
int res = 1e15;
while (l <= r) {
if (l % 2 == 1) {
res = min(res, tree[l]);l++;
}
if (r % 2 == 0) {
res = min(res, tree[r]);r--;
}
l /= 2;r /= 2;
}
return res;
}
};
int calcsum(int l, int r) {
//int rs = 0;
//for (int i = l; i <= r; ++i) {
// rs += i;
//}
//return rs % mod;
return (r * (r + 1) / 2 - l * (l - 1) / 2) % mod;
}
void solve() {
int n;
cin >> n;
vector<int> a(n);
vector<pair<int, int>> indsr(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
indsr[i] = {a[i], i};
}
sort(all(indsr));
segtree sg;
sg.make(a);
int reska = 0;
set<int> corel;
int corval = 0;
for (int i = 0; i < indsr.size(); ++i) {
sg.ch(indsr[i].second);
if (i + 1 != indsr.size() and indsr[i].first == indsr[i + 1].first) {
corel.insert(indsr[i].second);
} else {
corel.insert(indsr[i].second);
int lvl = 0, rvl = 0;
while (!corel.empty()) {
int x = *corel.begin();
int vl = sg.get(0, x - 1);
if (vl > 1e10)
corel.erase(x);
else {
lvl = vl;
break;
}
}
while (!corel.empty()) {
// cout << "FISH" << endl;
int x = *corel.rbegin();
int vl = sg.get(x+1, a.size() - 1);
if (vl > 1e10)
corel.erase(x);
else {
rvl = vl;
break;
}
}
//cout << "FISHA" << endl;
int sz = corel.size();
if (sz == 0)
continue;
pair<int, int> stpprc;
if (sz == 1)
stpprc = {lvl + rvl, 1};
else
stpprc = {min(lvl, rvl) * 2 + max(lvl, rvl) + sz * 3 - 3 - sz, sz * 3 - 3};
int mvtrg = indsr[i + 1].first - indsr[i].first;
//cout << mvtrg << ' ' << sz << ' ' << stpprc.first << ' ' << stpprc.second << '\n';
reska += stpprc.first % mod * mvtrg % mod;
reska += calcsum(indsr[i].first, indsr[i + 1].first - 1) * stpprc.second % mod;
}
}
reska %= mod;
cout << reska << '\n';
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int t = 1;
while (t--) {
solve();
}
}
詳細信息
Subtask #1:
score: 3
Accepted
Test #1:
score: 3
Accepted
time: 0ms
memory: 3580kb
input:
3 29 9 9
output:
0
result:
ok 1 number(s): "0"
Test #2:
score: 3
Accepted
time: 1ms
memory: 3576kb
input:
3 62 20 71
output:
7287
result:
ok 1 number(s): "7287"
Test #3:
score: 3
Accepted
time: 1ms
memory: 3804kb
input:
10 72 33 22 22 13 49 53 57 72 85
output:
40403
result:
ok 1 number(s): "40403"
Test #4:
score: 3
Accepted
time: 0ms
memory: 4000kb
input:
5000 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 97 97 97 97 9...
output:
481053
result:
ok 1 number(s): "481053"
Test #5:
score: 3
Accepted
time: 2ms
memory: 3936kb
input:
5000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
0
result:
ok 1 number(s): "0"
Test #6:
score: 3
Accepted
time: 2ms
memory: 3976kb
input:
5000 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2...
output:
12595
result:
ok 1 number(s): "12595"
Test #7:
score: 3
Accepted
time: 0ms
memory: 4232kb
input:
5000 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100...
output:
299
result:
ok 1 number(s): "299"
Test #8:
score: 3
Accepted
time: 0ms
memory: 3936kb
input:
5000 100 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
224232
result:
ok 1 number(s): "224232"
Test #9:
score: 3
Accepted
time: 2ms
memory: 3836kb
input:
5000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4...
output:
0
result:
ok 1 number(s): "0"
Test #10:
score: 3
Accepted
time: 0ms
memory: 3752kb
input:
5000 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 9...
output:
0
result:
ok 1 number(s): "0"
Test #11:
score: 3
Accepted
time: 2ms
memory: 3936kb
input:
5000 100 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4...
output:
499735
result:
ok 1 number(s): "499735"
Test #12:
score: 3
Accepted
time: 2ms
memory: 3884kb
input:
5000 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 9...
output:
461407
result:
ok 1 number(s): "461407"
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #13:
score: 0
Wrong Answer
time: 2ms
memory: 4228kb
input:
5000 37 39 93 78 85 71 59 21 57 96 61 59 23 16 57 90 13 59 85 70 62 67 78 97 16 60 8 48 28 53 4 24 1 97 97 98 57 87 96 91 74 54 100 76 86 86 46 39 100 57 70 76 73 55 84 93 64 6 84 39 75 94 30 15 3 31 11 34 27 10 6 81 30 76 60 9 4 47 1 88 17 71 61 30 19 10 4 57 79 37 22 74 84 8 91 58 15 45 7 98 32 46...
output:
217081
result:
wrong answer 1st numbers differ - expected: '216624', found: '217081'
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:
100%
Accepted
Dependency #2:
0%