QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#763415 | #964. Excluded Min | highkj | RE | 2ms | 11992kb | C++14 | 4.1kb | 2024-11-19 20:09:26 | 2024-11-19 20:09:27 |
Judging History
answer
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define rep(i,x,y) for(register int i=x;i<=y;i++)
#define rep1(i,x,y) for(register int i=x;i>=y;--i)
#define int long long
#define fire signed
#define il inline
template<class T> il void print(T x) {
if(x<0) printf("-"),x=-x;
if (x > 9) print(x / 10);
putchar(x % 10 + '0');
}
const int bufsize = 230005;
char buf[bufsize], *f1, *f2;
#define getchar() (f1 == f2 && (f2 = buf + fread(f1 = buf, 1, bufsize, stdin)) == buf? EOF: *f1++)
template<class T> il void in(T &x) {
x = 0; char ch = getchar();
int f = 1;
while (ch < '0' || ch > '9') {if(ch=='-') f = -1; ch = getchar(); }
while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar(); }
x *= f;
}
int T=1;
int n,q;
const int N=5e5+10,M=1e3+10;
struct node{
int l,r;
int Max,tag;
}tr[M][M<<2];
struct node1{
int l,r;
int sum,tag;
}tt[M<<2];
void up(int x,int id) {
tr[id][x].Max=max(tr[id][x<<1].Max,tr[id][x<<1|1].Max);
}
void build(int u,int l,int r,int id) {
tr[id][u]={l,r};
if(l==r) {
tr[id][u].Max=-l;
return ;
}
int mid=l+r>>1;
build(u<<1,l,mid,id);
build(u<<1|1,mid+1,r,id);
up(u,id);
}
void down(int x,int id) {
if(tr[id][x].tag) {
tr[id][x<<1].tag+=tr[id][x].tag;
tr[id][x<<1|1].tag+=tr[id][x].tag;
tr[id][x<<1|1].Max+=tr[id][x].tag;
tr[id][x<<1].Max+=tr[id][x].tag;
tr[id][x].tag=false;
}
}
void modify(int u,int l,int r,int k,int id) {
if(tr[id][u].l>=l&&tr[id][u].r<=r) {
tr[id][u].Max+=k;
tr[id][u].tag+=k;
return ;
}
down(u,id);
int mid=tr[id][u].l+tr[id][u].r>>1;
if(mid>=l) modify(u<<1,l,r,k,id);
if(mid<r) modify(u<<1|1,l,r,k,id);
up(u,id);
}
void build(int u,int l,int r) {
tt[u]={l,r};
if(l==r) return;
int mid=l+r>>1;
build(u<<1,l,mid);
build(u<<1|1,mid+1,r);
}
void down(int x) {
if(tt[x].tag) {
tt[x<<1].tag+=tt[x].tag;
tt[x<<1|1].tag+=tt[x].tag;
tt[x<<1].sum+=tt[x].tag;
tt[x<<1|1].sum+=tt[x].tag;
tt[x].tag=false;
}
}
void modify(int u,int l,int r,int k) {
if(tt[u].l>=l&&tt[u].r<=r) {
tt[u].sum+=k;
tt[u].tag+=k;
return ;
}
down(u);
int mid=tt[u].l+tt[u].r>>1;
if(mid>=l) modify(u<<1,l,r,k);
if(mid<r) modify(u<<1|1,l,r,k);
}
int Ans(int u,int x) {
if(tt[u].l==tt[u].r) return tt[u].sum;
down(u);
int mid=tt[u].l+tt[u].r>>1;
if(mid>=x) return Ans(u<<1,x);
return Ans(u<<1|1,x);
}
int Ans(int u,int x,int id) {
if(tr[id][u].l==tr[id][u].r) return tr[id][u].Max;
down(u,id);
int mid=tr[id][u].l+tr[id][u].r>>1;
if(mid>=x) return Ans(u<<1,x,id);
return Ans(u<<1|1,x,id);
}
int len;
struct QQ{
int l,r,id;
friend bool operator<(const QQ&a,const QQ&b) {
return a.l/len!=b.l/len?a.l<b.l:a.r<b.r;
}
}s[N];
int a[N],ll,ans[N],Max;
#define bl(x) ((x-1)/ll+1)
#define L(x) ((x-1)*ll+1)
#define R(x) min(Max,x*ll)
void add(int x) {
int itl=bl(x);
int bln=bl(Max);
modify(1,x,R(itl),1,itl);
itl++;
if(itl<=bln) modify(1,itl,bln,1);
}
void del(int x) {
int itl=bl(x);
int bln=bl(Max);
modify(1,x,R(itl),-1,itl);
itl++;
if(itl<=bln) modify(1,itl,bln,-1);
}
void solve() {
in(n),in(q);
rep(i,1,n) in(a[i]),a[i]++,Max=a[i];
Max=max(Max,n);
len=sqrt(n);
ll=sqrt(Max);
rep(i,1,q) {
in(s[i].l),in(s[i].r);
s[i].id=i;
}
sort(s+1,s+1+q);
rep(i,1,bl(Max)) build(1,L(i),R(i),i);
build(1,1,bl(Max));
int L=0,R=0;
L=1,R=n;
rep(i,1,n) add(a[i]);
// cout<<"faslfd\n";
rep(i,1,q) {
while(L>s[i].l) add(a[--L]);
while(L<s[i].l) del(a[L++]);
while(R<s[i].r) add(a[++R]);
while(R>s[i].r) del(a[R--]);
// cout<<L<<' '<<R<<endl;
// cout<<Ans(1,)
int lst=false,ss=0;
rep1(j,bl(Max),1) {
int id=tr[j][1].Max,pl=Ans(1,j);
id+=pl;
if(id>=0) {
lst=j;
ss=pl;
break;
}
}
int res=0;
rep(j,L(lst),R(lst)) {
if(ss+Ans(1,j,lst)>=0) {
res=j;
}
}
ans[s[i].id]=res;
}
rep(i,1,q) printf("%lld\n",ans[i]);
}
fire main() {
while(T--) {
solve();
}
return false;
}
/*
3 1
1 2 2
1 3
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 11992kb
input:
3 3 0 0 2 1 3 2 3 3 3
output:
3 1 0
result:
ok 3 number(s): "3 1 0"
Test #2:
score: 0
Accepted
time: 0ms
memory: 9960kb
input:
3 2 1 2 2 1 2 1 3
output:
0 3
result:
ok 2 number(s): "0 3"
Test #3:
score: 0
Accepted
time: 0ms
memory: 11960kb
input:
10 10 3 0 3 3 9 7 9 6 0 7 3 3 9 9 4 6 1 9 3 4 2 4 7 10 3 7 5 7 2 7
output:
0 1 0 5 0 1 1 0 0 1
result:
ok 10 numbers
Test #4:
score: 0
Accepted
time: 1ms
memory: 9940kb
input:
10 10 3 0 0 0 5 1 1 1 2 1 1 2 8 8 5 7 1 7 2 2 1 5 5 6 4 6 3 10 6 8
output:
1 0 2 7 1 4 0 2 8 3
result:
ok 10 numbers
Test #5:
score: -100
Runtime Error
input:
100 100 15 82 7 39 63 55 64 99 71 63 32 99 67 94 3 43 15 75 45 55 53 4 35 36 15 40 82 20 62 43 6 83 27 95 27 45 98 44 35 98 39 7 17 32 76 7 40 16 40 63 13 8 22 27 11 12 61 14 19 45 100 97 90 88 22 59 25 63 4 25 65 16 22 92 84 44 99 66 89 26 93 97 35 97 92 1 32 40 97 97 78 43 7 12 23 53 61 74 33 90 1...