QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#462797 | #140. Palembang Bridges | fryan | 0 | 4ms | 3604kb | C++20 | 2.3kb | 2024-07-04 04:36:03 | 2024-07-04 04:36:03 |
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,lsu=0;
node() {};
node(int lo, int hi) : lo(lo), hi(hi) {}
void push() {
if (!l) {
l = new node(lo,(lo+hi)/2);
r = new node((lo+hi)/2+1,hi);
}
if (lsu) {
l->range_add(lo,hi,lsu);
r->range_add(lo,hi,lsu);
lsu = 0;
}
va = l->va + r->va;
}
void range_add(int L, int R, int X) {
if (hi < L || R < lo) return;
if (L <= lo && hi <= R) {
va += (hi-lo+1)*X; lsu += X;
return;
}
push();
l->range_add(L,R,X);
r->range_add(L,R,X);
va = l->va + r->va;
}
int range_sum(int L, int R) {
if (hi < L || R < lo) return 0;
if (L <= lo && hi <= R) {
return va;
}
push();
return l->range_sum(L,R) + r->range_sum(L,R);
}
};
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), rt1(0,1e10);
vector<int> pt;
for (int i=0; i<ci; i++) {
cout << "star" << endl;
int s=br[i][0],e=br[i][1];
rt.range_add(s,s,s);
rt.range_add(e,e,e);
rt1.range_add(s,s,1);
rt1.range_add(e,e,1);
pt.push_back(s);
pt.push_back(e);
cout << "fin" << endl;
}
if (sz(pt)) {
sort(all(pt));
int m = pt[sz(pt)/2];
int c1 = rt1.range_sum(0,m);
int s1 = rt.range_sum(0,m);
int c2 = rt1.range_sum(m+1,2e9);
int s2 = rt.range_sum(m+1,2e9);
cout << m*c1-s1 + s2-m*c2 + ans;
} else {
cout << ans;
}
}
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 8
Accepted
time: 1ms
memory: 3560kb
input:
1 1 B 426311872 B 741424667
output:
315112795
result:
ok single line: '315112795'
Test #2:
score: -8
Wrong Answer
time: 4ms
memory: 3604kb
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:
star fin star fin star fin star fin star fin star fin star fin star fin star fin star fin star fin star fin star fin star fin star fin star fin star fin star fin star fin star fin star fin star fin star fin star fin star fin star fin star fin star fin star fin star fin star fin star fin star fin sta...
result:
wrong answer 1st lines differ - expected: '659000001000', found: 'star'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #22:
score: 0
Wrong Answer
time: 0ms
memory: 3556kb
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%