QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#585177 | #140. Palembang Bridges | isirazeev | 0 | 6ms | 10176kb | C++20 | 2.6kb | 2024-09-23 19:32:14 | 2024-09-23 19:32:15 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int maxC = (int) 1e9 + 1;
struct Node {
long long val, add;
Node *l, *r;
Node() : val(0), add(0), l(nullptr), r(nullptr) {};
};
void createSon(Node *v) {
if (v->l == nullptr)
v->l = new Node();
if (v->r == nullptr)
v->r = new Node();
}
void push(Node *v, int l, int r) {
if (v->add == 0) return;
v->val += v->add * (long long) (r - l + 1);
if (l != r) {
createSon(v);
v->l->add += v->add, v->r->add += v->add;
}
v->add = 0;
}
void update(Node *v, int l, int r, int tl, int tr, int add) {
push(v, l, r);
if (l > tr || r < tl)
return;
if (l >= tl && r <= tr) {
v->add += add;
push(v, l, r);
return;
}
int mid = (l + r) / 2;
createSon(v);
update(v->l, l, mid, tl, tr, add);
update(v->r, mid + 1, r, tl, tr, add);
v->val = v->l->val + v->r->val;
}
long long get_sum(Node *v, int l, int r, int tl, int tr) {
push(v, l, r);
if (l > tr || r < tl)
return 0;
if (l >= tl && r <= tr)
return v->val;
int mid = (l + r) / 2;
createSon(v);
return get_sum(v->l, l, mid, tl, tr)
+ get_sum(v->r, mid + 1, r, tl, tr);
}
void Add(Node *v, int x) {
update(v, 0, maxC, 1, x, -1);
update(v, 0, maxC, 0, 0, x);
update(v, 0, maxC, x + 1, maxC, 1);
}
void Del(Node *v, int x) {
update(v, 0, maxC, 1, x - 1, 1);
update(v, 0, maxC, 0, 0, -x);
update(v, 0, maxC, x + 1, maxC, -1);
}
long long get(Node *v, int x) {
return get_sum(v, 0, maxC, 0, x);
}
Node *r1 = new Node(), *r2 = new Node();
long long find_ans(Node *v) {
int l = 0, r = maxC;
while (r - l > 1) {
int mid = (l + r) / 2;
if (get(v, mid) <= get(v, mid - 1)) l = mid;
else r = mid;
}
return get(v, l);
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int k, n, add = 0;
cin >> k >> n;
vector<int> s, t;
for (int i = 0; i < n; i++) {
char p, q;
int S, T;
cin >> p >> S >> q >> T;
if (S < T) swap(S, T);
if (p == q) {
add += S - T;
} else {
s.emplace_back(S), t.emplace_back(T);
}
}
n = (int) s.size();
if (n == 0) {
cout << add;
return 0;
}
if (k == 1) {
for (int i = 0; i < n; i++)
Add(r1, s[i]), Add(r1, t[i]);
cout << find_ans(r1) + add + n;
return 0;
}
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 8
Accepted
time: 0ms
memory: 3588kb
input:
1 1 B 426311872 B 741424667
output:
315112795
result:
ok single line: '315112795'
Test #2:
score: 8
Accepted
time: 3ms
memory: 3636kb
input:
1 1000 A 1000000000 B 1000000000 B 1000000000 A 1000000000 A 500000000 B 500000000 A 1000000000 B 1000000000 B 0 A 0 A 500000000 B 500000000 B 0 A 0 A 1000000000 B 1000000000 A 500000000 B 500000000 A 1000000000 B 1000000000 B 1000000000 A 1000000000 A 0 B 0 B 0 A 0 B 0 A 0 A 500000000 B 500000000 B...
output:
659000001000
result:
ok single line: '659000001000'
Test #3:
score: 8
Accepted
time: 4ms
memory: 3924kb
input:
1 1000 A 500000001 B 500000000 A 500000002 B 500000003 A 500000005 B 500000004 A 1 B 0 B 500000007 A 500000006 A 500000009 B 500000008 B 500000010 A 500000011 B 1000000000 A 999999999 A 3 B 2 B 499999988 A 499999989 A 999999998 B 999999997 B 4 A 5 B 7 A 6 A 9 B 8 A 10 B 11 B 999999996 A 999999995 A ...
output:
649999819818
result:
ok single line: '649999819818'
Test #4:
score: 8
Accepted
time: 0ms
memory: 3744kb
input:
1 4 B 90 B 72 A 68 A 90 A 15 A 42 A 45 A 15
output:
97
result:
ok single line: '97'
Test #5:
score: 8
Accepted
time: 0ms
memory: 3612kb
input:
1 1000 A 0 B 1 A 1 B 0 A 0 B 1 B 0 A 0 B 1 B 1 B 0 A 0 A 1 B 1 A 1 B 1 A 1 B 0 A 0 B 1 A 0 B 0 B 1 A 1 B 0 A 0 B 0 A 0 A 1 B 0 A 1 B 0 B 1 A 0 B 0 A 0 A 1 B 1 A 1 B 1 B 0 A 1 B 0 A 1 A 0 B 1 B 0 A 1 A 1 B 0 A 1 B 1 B 1 A 0 B 1 A 0 B 1 A 0 A 1 B 0 A 0 B 1 A 0 B 1 A 0 B 0 B 0 A 0 A 1 B 1 B 0 A 1 B 0 A...
output:
1969
result:
ok single line: '1969'
Test #6:
score: 8
Accepted
time: 6ms
memory: 6468kb
input:
1 1000 A 598246 B 85766 B 457924 A 841963 B 107690 A 39924 B 814042 A 328853 B 518897 A 548739 B 633776 A 181927 A 985484 B 773931 A 698975 B 526021 A 846547 B 258759 B 778661 A 181322 B 131489 A 151052 A 669218 B 314136 B 562707 A 887236 B 47953 A 880429 A 251615 B 488724 B 734021 A 487209 B 492935...
output:
497401257
result:
ok single line: '497401257'
Test #7:
score: 0
Wrong Answer
time: 4ms
memory: 10176kb
input:
1 967 B 209071192 A 810324333 A 603292190 B 990286906 B 76624835 A 1764783 B 38843365 A 66481975 B 506328820 A 854781128 B 601820095 A 20961640 B 953337305 A 762377474 B 472547211 A 248665021 A 908090176 B 277738137 B 523090586 A 193277212 B 824206700 A 342446509 B 845969410 A 191939894 A 472429676 ...
output:
466501712796
result:
wrong answer 1st lines differ - expected: '470796680092', found: '466501712796'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #22:
score: 9
Accepted
time: 0ms
memory: 3592kb
input:
2 1 B 822190955 B 309099167
output:
513091788
result:
ok single line: '513091788'
Test #23:
score: 0
Wrong Answer
time: 0ms
memory: 3580kb
input:
2 100 A 699479271 B 699479270 B 999432953 A 999432956 A 657124443 B 657124444 B 928721383 A 928721383 B 809218485 A 809218487 B 220719335 A 220719338 B 93242937 A 93242943 A 566737518 B 566737523 A 751211620 B 751211614 B 799605314 A 799605321 A 634052514 B 634052513 B 681923789 A 681923799 B 377862...
output:
result:
wrong answer 1st lines differ - expected: '22963819679', found: ''
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%