QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#107340#6104. Building Bombingbulijiojiodibuliduo#WA 2ms3760kbC++2.6kb2023-05-21 00:18:072023-05-21 00:18:11

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-21 00:18:11]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3760kb
  • [2023-05-21 00:18:07]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef basic_string<int> BI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=101000;
int n,l,k,h[N];
struct node {
	int fg,mv;
}nd[4*N];
void upd(int p) {
	nd[p].mv=min(nd[p+p].mv,nd[p+p+1].mv);
}
void setf(int p,int v) {
	nd[p].fg+=v;
	nd[p].mv+=v;
}
void build(int p,int l,int r) {
	nd[p].fg=0;
	nd[p].mv=1<<30;
	if (l==r) {
	} else {
		int md=(l+r)>>1;
		build(p+p,l,md);
		build(p+p+1,md+1,r);
		upd(p);
	}
}
void push(int p) {
	if (nd[p].fg) {
		setf(p+p,nd[p].fg);
		setf(p+p+1,nd[p].fg);
		nd[p].fg=0;
	}
}
int query(int p,int l,int r,int tl,int tr) {
	if (tl==l&&tr==r) return nd[p].mv;
	else {
		push(p);
		int md=(l+r)>>1;
		if (tr<=md) return query(p+p,l,md,tl,tr);
		else if (tl>md) return query(p+p+1,md+1,r,tl,tr);
		else return min(query(p+p,l,md,tl,md),query(p+p+1,md+1,r,md+1,tr));
	}
}
void modify(int p,int l,int r,int tl,int tr,int v) {
	if (tl>tr) return;
	if (tl==l&&tr==r) return setf(p,v);
	else {
		push(p);
		int md=(l+r)>>1;
		if (tr<=md) modify(p+p,l,md,tl,tr,v);
		else if (tl>md) modify(p+p+1,md+1,r,tl,tr,v);
		else modify(p+p,l,md,tl,md,v),modify(p+p+1,md+1,r,md+1,tr,v);
		upd(p);
	}
}

void change(int p,int l,int r,int x,int v) {
	if (l==r) nd[p].mv=v;
	else {
		push(p);
		int md=(l+r)>>1;
		if (x<=md) change(p+p,l,md,x,v);
		else change(p+p+1,md+1,r,x,v);
		upd(p);
	}
}

int dp[14][N];
int main() {
	scanf("%d%d%d",&n,&l,&k);
	int m=0;
	vector<PII> v;
	rep(i,1,n+1) {
		scanf("%d",&h[i]);
		if (i>l&&h[i]>h[l]) v.pb(mp(-h[i],++m));
	}
	n=m;
	sort(all(v));
	rep(i,0,m) {
		h[v[i].se]=m-i;
	}
	++n; h[n]=n;
	//rep(i,1,n+1) printf("%d ",h[i]); puts("");
	rep(i,1,n+1) dp[0][i]=i-1;
	rep(j,1,k) {
		build(1,0,n);
		rep(i,1,n+1) {
			dp[j][i]=query(1,0,n,0,h[i]-1);
			modify(1,0,n,0,h[i]-1,1);
			change(1,0,n,h[i],dp[j-1][i]);
			//printf("%d %d %d\n",j,i,dp[j][i]);
		}
	}
	int ans=dp[k-1][n];
	if (ans>n) ans=-1;
	printf("%d\n",ans);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3592kb

input:

7 2 3
10 30 90 40 60 60 80

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

input:

3 2 2
30 20 10

output:

-1

result:

ok 1 number(s): "-1"

Test #3:

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

input:

1 1 1
608954134

output:

0

result:

ok 1 number(s): "0"

Test #4:

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

input:

10 5 3
872218248 517822599 163987167 517822599 458534407 142556631 142556631 458534407 458534407 872218248

output:

-1

result:

ok 1 number(s): "-1"

Test #5:

score: -100
Wrong Answer
time: 2ms
memory: 3732kb

input:

10 4 2
31201623 546478688 709777934 672927273 672927273 709777934 801718395 672927273 926114576 38983342

output:

2

result:

wrong answer 1st numbers differ - expected: '3', found: '2'