QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#118414#1132. Financial Reportlmeowdn#0 89ms52612kbC++142.8kb2023-07-03 15:04:432024-05-31 18:53:23

Judging History

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

  • [2024-05-31 18:53:23]
  • 评测
  • 测评结果:0
  • 用时:89ms
  • 内存:52612kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-03 15:04:43]
  • 提交

answer

#include<bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
template<typename T,typename U>
T ceil(T x, U y) {return (x>0?(x+y-1)/y:x/y);}
template<typename T,typename U>
T floor(T x, U y) {return (x>0?x/y:(x-y+1)/y);}
template<class T,class S>
bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}
template<class T,class S>
bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}
int popcnt(int x) {return __builtin_popcount(x);}
int popcnt(ll x)  {return __builtin_popcountll(x);}
int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}
int topbit(ll x)  {return (x==0?-1:63-__builtin_clzll(x));}
int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}
int lowbit(ll x)  {return (x==0?-1:__builtin_ctzll(x));}

#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii; 
typedef vector<int> vi;
typedef vector<pii> vp;
typedef tuple<int,int,int> tiii;
int read() {
  int x=0,w=1; char c=getchar(); 
  while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
  while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();}
  return x*w;
}

const int N=3e5+5;
int n,D,a[N],b[N],c[N],cnt,f[N],p[N],mx[21][N],ans,s[N];
vi v[N];

int lb(int x) {return x&-x;}
void add(int x,int y) {for(;x<=cnt;x+=lb(x)) chmax(s[x],y);}
void clear(int x) {for(;x<=cnt;x+=lb(x)) s[x]=0;}
int qrys(int x,int y=0) {for(;x;x-=lb(x)) chmax(y,s[x]); return y;}

int qmin(int l,int r) {
  int h=__lg(r-l+1);
  return min(mx[h][l],mx[h][r-(1<<h)+1]);
}
int qmax(int l,int r) {
  int h=__lg(r-l+1); if(l>r) return -1;
  return max(mx[h][l],mx[h][r-(1<<h)+1]);
}

void work(int l,int r) {
  if(l==r) {chmax(f[l],1), chmax(ans,f[l]); return;} int mid=l+r>>1;
  work(l,mid);
  rep(i,l,mid) v[i].clear();
  rep(i,mid+1,r) if(p[i]<=mid) v[max(l,p[i])].eb(i);
  per(i,mid,l) {
    add(a[i],f[i]+1);
    for(int x:v[i]) chmax(f[x],qrys(a[x]-1));
  }
  per(i,mid,l) clear(a[i]);
  work(mid+1,r);
}

signed main() {
  n=read(), D=read();
  rep(i,1,n) a[i]=read(), c[i]=a[i];
  sort(c+1,c+n+1); cnt=unique(c+1,c+n+1)-c-1;
  rep(i,1,n) a[i]=lower_bound(c+1,c+n+1,a[i])-c;
  rep(i,1,n) mx[0][i]=a[i];
  rep(h,1,20) rep(i,1,n) if(i+(1<<h)-1<=n)
    mx[h][i]=min(mx[h-1][i],mx[h-1][i+(1<<h-1)]);
  rep(i,1,n-D) b[i]=qmin(i,i+D-1), mx[0][i]=b[i];
  rep(h,1,20) rep(i,1,n) if(i+(1<<h)-1<=n)
    mx[h][i]=max(mx[h-1][i],mx[h-1][i+(1<<h-1)]);
  rep(i,2,n) {
    if(i<=D) p[i]=1;
    else {
      int l=1, r=i-D;
      while(l<=r) {
        int mid=l+r>>1;
        if(qmax(mid+1,i-D)<a[i]) p[i]=mid, r=mid-1;
        else l=mid+1;
      }
    }
  }
  work(1,n);
  printf("%d\n",ans);
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 14
Accepted
time: 0ms
memory: 14220kb

input:

1 1
314159265

output:

1

result:

ok single line: '1'

Test #2:

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

input:

1 1
0

output:

1

result:

ok single line: '1'

Test #3:

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

input:

1 1
1000000000

output:

1

result:

ok single line: '1'

Test #4:

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

input:

2 1
299792458 299792458

output:

1

result:

ok single line: '1'

Test #5:

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

input:

2 1
141421356 173205080

output:

2

result:

ok single line: '2'

Test #6:

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

input:

2 1
244948974 223606797

output:

1

result:

ok single line: '1'

Test #7:

score: 0
Accepted
time: 3ms
memory: 18420kb

input:

2 2
299792458 299792458

output:

1

result:

ok single line: '1'

Test #8:

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

input:

2 2
141421356 173205080

output:

2

result:

ok single line: '2'

Test #9:

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

input:

2 2
244948974 223606797

output:

1

result:

ok single line: '1'

Test #10:

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

input:

3 1
500000000 1000000000 0

output:

2

result:

ok single line: '2'

Test #11:

score: 0
Accepted
time: 4ms
memory: 17924kb

input:

3 2
500000000 1000000000 0

output:

2

result:

ok single line: '2'

Test #12:

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

input:

4 1
0 1000000000 200000000 500000000

output:

2

result:

ok single line: '2'

Test #13:

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

input:

4 2
0 1000000000 200000000 500000000

output:

3

result:

ok single line: '3'

Test #14:

score: 0
Accepted
time: 4ms
memory: 20192kb

input:

5 2
111111111 888888888 555555555 222222222 444444444

output:

2

result:

ok single line: '2'

Test #15:

score: -14
Wrong Answer
time: 0ms
memory: 23660kb

input:

19 1
876813783 876813783 294665595 1000000000 515198511 876813783 876813783 294665595 403855901 439947219 439947219 403855901 581007064 294665595 1000000000 581007064 294665595 865289906 865289906

output:

4

result:

wrong answer 1st lines differ - expected: '5', found: '4'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #62:

score: 12
Accepted
time: 57ms
memory: 49728kb

input:

300000 1
285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 2...

output:

1

result:

ok single line: '1'

Test #63:

score: -12
Wrong Answer
time: 75ms
memory: 47748kb

input:

299971 1
213313757 312061773 790195557 213313757 0 790195557 30936680 832403554 312061773 30936680 0 213313757 329317874 329317874 0 0 329317874 329317874 0 213313757 329317874 790195557 832403554 832403554 329317874 312061773 832403554 832403554 329317874 329317874 312061773 790195557 790195557 790...

output:

1

result:

wrong answer 1st lines differ - expected: '7', found: '1'

Subtask #5:

score: 0
Wrong Answer

Test #76:

score: 5
Accepted
time: 49ms
memory: 50588kb

input:

300000 300000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 ...

output:

1

result:

ok single line: '1'

Test #77:

score: -5
Wrong Answer
time: 89ms
memory: 52612kb

input:

299994 299994
799095588 515641284 851040998 371590609 581412250 114983578 870953189 65883574 114983578 546636247 675572999 416143410 763181943 799095588 564152084 521371792 455808474 799095588 870953189 839155298 684313832 605076527 675572999 219704773 684313832 372618560 875093839 41381734 11498357...

output:

1

result:

wrong answer 1st lines differ - expected: '85', found: '1'

Subtask #6:

score: 0
Skipped

Dependency #1:

0%