QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#462796#140. Palembang Bridges fryan0 1ms3788kbC++202.2kb2024-07-04 04:33:562024-07-04 04:33:59

Judging History

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

  • [2024-07-04 04:33:59]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3788kb
  • [2024-07-04 04:33:56]
  • 提交

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++) {
			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);
		}
		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;
	}
	
	return 0;
}

详细

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

input:

1 1
B 426311872 B 741424667

output:


result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #22:

score: 0
Wrong Answer
time: 1ms
memory: 3788kb

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%