QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#217016 | #6553. Shared Memory Switch | 275307894a | RE | 3ms | 13780kb | C++14 | 2.0kb | 2023-10-16 11:15:10 | 2023-10-16 11:15:10 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__uint128_t;
const int N=2e5+5,M=N*8+5,K=600+5,mod=998244353,Mod=mod-1;const db eps=1e-6;const int INF=1e9+7;mt19937 rnd(263082);
int n,m;
priority_queue<pii > q[N];
set<pii> Q;
namespace Tree{
#define ls v<<1
#define rs v<<1|1
int f[M],g[M];
void Up(int v){f[v]=min(f[ls],f[rs])-g[v];}
void BD(int l=1,int r=2*n,int v=1){
f[v]=m;if(l==r) return;int m=l+r>>1;
BD(l,m,ls);BD(m+1,r,rs);
}
void Add(int x,int y,int l=1,int r=2*n,int v=1){
if(x<=l&&r<=y) {g[v]++;f[v]--;return;}int m=l+r>>1;
x<=m&&(Add(x,y,l,m,ls),0);y>m&&(Add(x,y,m+1,r,rs),0);Up(v);
}
int qry(int x,int y,int l=1,int r=2*n,int v=1){
if(x<=l&&r<=y) return f[v];int m=l+r>>1;
return min(x<=m?qry(x,y,l,m,ls):INF,y>m?qry(x,y,m+1,r,rs):INF)-g[v];
}
#undef ls
#undef rs
}
void Del(int x){
if(!q[x].empty()) Q.erase(make_pair(q[x].top().fi,x));
}
void Ins(int x){
if(!q[x].empty()) Q.emplace(q[x].top().fi,x);
}
void Solve(){
int i,j;scanf("%d%d",&n,&m);
vector<int> ans;
int Ct=1;
Tree::BD();
for(i=1;i<=2*n;i++){
int x;if(i<=n) scanf("%d",&x);else x=-1;
if(~x){Del(x);q[x].emplace(Ct,i);Ins(x);continue;}
vector<int> E;
while(!Q.empty()){
auto p=*Q.rbegin();Q.erase(p);
if(!Tree::qry(p.fi,Ct)) break;
E.emplace_back(p.se);ans.emplace_back(q[p.se].top().se);q[p.se].pop();
Tree::Add(p.fi,Ct);
}
for(int j:E) Ins(j);
++Ct;
}
printf("%d\n",ans.size());
for(int i:ans) printf("%d ",i);
}
int main(){
int t=1;
// scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 13580kb
input:
14 5 1 1 1 2 2 2 -1 1 -1 1 -1 1 -1 1
output:
9 6 3 8 5 10 4 12 14 2
result:
ok n=14
Test #2:
score: 0
Accepted
time: 2ms
memory: 13780kb
input:
14 4 1 1 1 2 2 2 -1 1 -1 1 -1 1 -1 1
output:
8 6 3 8 5 10 4 12 14
result:
ok n=14
Test #3:
score: -100
Runtime Error
input:
0 0