QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#462801#140. Palembang Bridges fryan8 56ms35812kbC++202.3kb2024-07-04 04:50:402024-07-04 04:50:41

Judging History

你现在查看的是最新测评结果

  • [2024-07-04 04:50:41]
  • 评测
  • 测评结果:8
  • 用时:56ms
  • 内存:35812kb
  • [2024-07-04 04:50:40]
  • 提交

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 push() {
		if (!l) {
			l = new node(lo,(lo+hi)/2);
			r = new node((lo+hi)/2+1,hi);
		}
	}
	void point_add(int I, int X) {
		if (lo == I && I == hi) {
			amt++;
			va += X;
		} else {
			push();
			int m = (lo+hi)/2;
			if (I <= m) {
				l->point_add(I,X);
			} else {
				r->point_add(I,X);
			}
			amt = l->amt + r->amt;
			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);
	}
	int range_cnt(int L, int R) {
		if (hi < L || R < lo) return 0;
		if (L <= lo && hi <= R) {
			return amt;
		}
		push();
		return l->range_cnt(L,R) + r->range_cnt(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);
		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: 8
Accepted

Test #1:

score: 8
Accepted
time: 1ms
memory: 3636kb

input:

1 1
B 426311872 B 741424667

output:

315112795

result:

ok single line: '315112795'

Test #2:

score: 0
Accepted
time: 1ms
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:

659000001000

result:

ok single line: '659000001000'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3892kb

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: 0
Accepted
time: 0ms
memory: 3500kb

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: 0
Accepted
time: 1ms
memory: 3616kb

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: 0
Accepted
time: 3ms
memory: 5808kb

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
Accepted
time: 4ms
memory: 8224kb

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:

470796680092

result:

ok single line: '470796680092'

Test #8:

score: 0
Accepted
time: 1ms
memory: 3680kb

input:

1 1000
B 0 A 1000000000
B 0 A 1000000000
B 1000000000 A 0
A 1000000000 B 0
B 0 A 1000000000
B 0 A 1000000000
A 0 B 1000000000
B 0 A 1000000000
B 0 A 1000000000
B 0 A 1000000000
B 0 A 1000000000
A 1000000000 B 0
B 0 A 1000000000
B 0 A 1000000000
A 1000000000 B 0
B 1000000000 A 0
B 1000000000 A 0
B 0 ...

output:

1000000001000

result:

ok single line: '1000000001000'

Test #9:

score: 0
Accepted
time: 0ms
memory: 8440kb

input:

1 1000
A 126148 B 138629
A 1956796 B 1961512
A 2467612 B 2976963
B 3231056 A 3187470
B 4485092 A 4805418
A 5815768 B 5012466
B 6709826 A 6631652
A 7384525 B 7982443
A 8702501 B 8083053
A 9750494 B 9414146
B 10511913 A 10300242
A 11414967 B 11792128
B 12453829 A 12271791
A 13801488 B 13139841
B 14570...

output:

499992449655

result:

ok single line: '499992449655'

Test #10:

score: 0
Accepted
time: 1ms
memory: 3908kb

input:

1 1000
B 1000000000 A 0
B 1 A 999999999
A 999999998 B 2
A 999999997 B 3
A 999999996 B 4
B 5 A 999999995
B 6 A 999999994
A 7 B 999999993
B 999999992 A 8
A 9 B 999999991
A 999999990 B 10
A 11 B 999999989
B 12 A 999999988
A 13 B 999999987
B 14 A 999999986
A 999999985 B 15
B 999999984 A 16
B 17 A 999999...

output:

999999002000

result:

ok single line: '999999002000'

Test #11:

score: 0
Accepted
time: 3ms
memory: 6412kb

input:

1 1000
A 639022834 B 639022825
B 164875881 A 164875889
A 345973409 B 345973410
B 650643813 A 650643816
A 218804569 B 218804573
B 60886574 A 60886583
B 829040885 A 829040890
B 340211580 A 340211573
B 783059185 A 783059177
B 994262398 A 994262399
B 427304481 A 427304486
A 373191501 B 373191501
A 65190...

output:

498415265474

result:

ok single line: '498415265474'

Subtask #2:

score: 0
Memory Limit Exceeded

Dependency #1:

100%
Accepted

Test #12:

score: 14
Accepted
time: 47ms
memory: 6736kb

input:

1 100000
B 0 A 0
A 1 B 0
B 0 A 0
A 1 B 0
B 1 A 0
B 1 A 1
B 1 A 0
A 0 B 0
B 1 A 0
B 1 A 0
B 1 A 0
B 0 A 1
B 0 A 0
B 0 A 1
A 0 B 1
B 1 A 0
A 1 B 1
B 0 A 0
A 0 B 0
A 1 B 1
B 1 A 0
B 0 A 1
A 0 B 0
A 0 B 1
B 1 A 0
A 0 B 1
A 0 B 0
A 1 B 0
A 1 B 1
A 1 B 0
B 1 A 0
A 1 B 0
A 0 B 0
B 0 A 1
B 1 A 0
A 0 B 1
A 0...

output:

199907

result:

ok single line: '199907'

Test #13:

score: 0
Accepted
time: 56ms
memory: 35812kb

input:

1 100000
A 999999999 B 1000000000
A 1 B 0
B 3 A 2
A 4 B 5
A 999999998 B 999999997
A 500000000 B 500000001
B 999999995 A 999999996
B 999999993 A 999999994
A 500000002 B 500000003
A 500000005 B 500000004
B 500000007 A 500000006
A 999999991 B 999999992
A 7 B 6
A 999999989 B 999999990
B 499999993 A 4999...

output:

66818736664678

result:

ok single line: '66818736664678'

Test #14:

score: -14
Memory Limit Exceeded

input:

1 100000
A 999933197 B 922319427
B 358973258 A 110896122
B 790706905 A 700578466
A 261833979 B 174780238
B 527377624 A 790157498
A 712098182 B 434767355
B 649365576 A 222614576
B 524821299 A 224370351
B 634735585 A 55865839
A 423764322 B 340889518
A 366912717 B 836451240
A 284261689 B 409476293
B 55...

output:

50064192028779

result:


Subtask #3:

score: 0
Wrong Answer

Test #22:

score: 0
Wrong Answer
time: 0ms
memory: 3608kb

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%