QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#462805 | #140. Palembang Bridges | fryan | 0 | 1ms | 3856kb | C++20 | 2.5kb | 2024-07-04 04:56:43 | 2024-07-04 04:56:43 |
answer
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define int long long
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
struct node {
node *l=0,*r=0;
int lo,hi,va=0,amt=0;
node() {};
node(int lo, int hi) : lo(lo), hi(hi) {}
void point_add(int I, int X) {
if (lo == I && I == hi) {
amt++;
va += X;
} else {
int m = (lo+hi)/2;
if (I <= m) {
if (!l) {
l = new node(lo,(lo+hi)/2);
}
l->point_add(I,X);
} else {
if (!r) {
r = new node((lo+hi)/2+1,hi);
}
r->point_add(I,X);
}
int asu = 0, vsu = 0;
if (l) {
asu += l->amt;
vsu += r->va;
}
if (r) {
asu += r->amt;
vsu += r->va;
}
amt = asu;
va = vsu;
}
}
int range_sum(int L, int R) {
if (hi < L || R < lo) return 0;
if (L <= lo && hi <= R) {
return va;
}
int su=0;
if (l) {
su += l->range_sum(L,R);
}
if (r) {
su += r->range_sum(L,R);
}
return su;
}
int range_cnt(int L, int R) {
if (hi < L || R < lo) return 0;
if (L <= lo && hi <= R) {
return amt;
}
int su=0;
if (l) {
su += l->range_cnt(L,R);
}
if (r) {
su += r->range_cnt(L,R);
}
return su;
}
};
const int mxn = 1e5;
int k,n;
array<int,2> br[mxn];
int ans=0;
bool ccb(const array<int,2> &a, const array<int,2> &b) {
return ((a[0]+a[1]) < (b[0]+b[1]));
}
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin>>k>>n; int ci=0;
for (int i=0; i<n; i++) {
char t1,t2; int p1,p2;
cin>>t1>>p1>>t2>>p2;
if (t1 == t2) {
ans += abs(p2-p1);
} else {
br[ci++]={p1,p2};
ans++;
}
}
sort(br,br+ci,ccb);
if (k==1) {
node rt(0,1e10);
vector<int> pt;
for (int i=0; i<ci; i++) {
int s=br[i][0],e=br[i][1];
rt.point_add(s,s);
rt.point_add(e,e);
pt.push_back(s);
pt.push_back(e);
}
if (sz(pt)) {
sort(all(pt));
int m = pt[sz(pt)/2];
int c1 = rt.range_cnt(0,m);
int s1 = rt.range_sum(0,m);
int c2 = rt.range_cnt(m+1,2e9);
int s2 = rt.range_sum(m+1,2e9);
cout << m*c1-s1 + s2-m*c2 + ans;
} else {
cout << ans;
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 8
Accepted
time: 1ms
memory: 3640kb
input:
1 1 B 426311872 B 741424667
output:
315112795
result:
ok single line: '315112795'
Test #2:
score: -8
Runtime Error
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:
result:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #22:
score: 0
Wrong Answer
time: 0ms
memory: 3856kb
input:
2 1 B 822190955 B 309099167
output:
result:
wrong answer 1st lines differ - expected: '513091788', found: ''
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%