QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#107341 | #6104. Building Bombing | bulijiojiodibuliduo# | WA | 3ms | 3672kb | C++ | 2.6kb | 2023-05-21 00:21:14 | 2023-05-21 00:21:17 |
Judging History
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;
int cc=0;
rep(i,1,n+1) {
scanf("%d",&h[i]);
if (i>l&&h[i]>h[l]) v.pb(mp(-h[i],++m));
if (i<l&&h[i]>=h[l]) ++cc;
}
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]+cc;
if (ans>n) ans=-1;
printf("%d\n",ans);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 3672kb
input:
7 2 3 10 30 90 40 60 60 80
output:
5 1 3 2 4 6 1 1 1073741824 1 2 1073741825 1 3 1 1 4 2 1 5 2 1 6 0 2 1 1073741824 2 2 1073741825 2 3 1073741825 2 4 1073741826 2 5 1 2 6 2 3
result:
wrong answer 1st numbers differ - expected: '2', found: '5'