QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#318355 | #3558. Constellation 3 | toj | 0 | 0ms | 17508kb | C++11 | 1.2kb | 2024-01-31 09:11:33 | 2024-01-31 09:11:33 |
Judging History
answer
// S2OJ Submission #1196 @ 1706663492276
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 1;
int n, m, ans;
vector<int> z[N];
vector<pair<int, int>> st[N];
struct Bcj {
vector<int> fa;
Bcj(int num) : fa(num) {for (int i = 1; i <= n; ++i) fa[i] = i;}
int find(int x) {return x == fa[x] ? x : find(fa[x]);}
};
struct Szsz {
#define lowbit(i) i & -i
vector<int> t;
Szsz(int num) : t(num) {}
int getsum(int i) {
int sum = 0;
for (; i; i -= lowbit(i))
sum += t[i];
return sum;
}
void add(int i, int x) {
for (; i <= n; i += lowbit(i))
t[i] += x;
}
};
signed main() {
cin >> n;
for (int i = 1; i <= n; ++i) {
int a; cin >> a;
z[a].push_back(i);
}
cin >> m;
for (int i = 1; i <= m; ++i) {
int x, y, c; cin >> x >> y >> c;
st[y].push_back(make_pair(x, c));
}
Bcj L(N), R(N);
Szsz cost(N);
for (int y = 1; y <= n; ++y) {
for (auto star : st[y]) {
int x = star.first, c = star.second;
int C = cost.getsum(x);
if (c <= C)
ans += c;
else {
ans += C;
cost.add(L.find(x)+1, c-C);
cost.add(R.find(x)+1, C-c);
}
}
for (int x : z[y])
L.fa[x] = x-1, R.fa[x] = x+1;
}
cout << ans << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 17508kb
input:
297 296 275 40 154 200 77 201 106 133 163 127 268 225 154 27 202 272 176 133 116 151 11 262 281 188 152 249 53 133 106 160 62 104 210 54 201 184 110 199 217 155 193 168 239 277 22 230 187 201 14 85 100 159 129 69 241 150 10 20 263 285 76 219 52 40 241 126 182 23 55 243 145 203 163 251 243 13 292 249...
output:
1784273
result:
wrong answer 1st lines differ - expected: '4354552', found: '1784273'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%