提出 #44116365
ソースコード 拡げる
/*
hmz is cute!
--------------------------------------------
You've got to have faith
Don't let them cut you down cut you down once more
*/
#include<bits/stdc++.h>
using namespace std;
#define TY long long
#define IL inline
#define umap unordered_map
#define ull unsigned long long
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define mod (TY)(1e9+7)
#define MAXN 500005
#define MAXM 200005
#define MAXK 27
#define INF (TY)(1e9)
#define block 300
#define For(i,a,b) for(TY i=(a);i<=(b);++i)
#define FOR(i,a,b) for(TY i=(a);i<(b);++i)
#define Rof(i,a,b) for(TY i=(a);i>=(b);--i)
#define ROF(i,a,b) for(TY i=(a);i>(b);--i)
IL TY qr(){
TY x=0,f=1;char op=getchar();
for(;op<'0'||op>'9';op=getchar())if(op=='-')f=-1;
for(;op>='0'&&op<='9';op=getchar())x=x*10+(op^48);
return x*f;
}IL bool ischar(char op){
if(op>='a'&&op<='z')return true;
if(op>='A'&&op<='Z')return true;
return false;
}IL char getc(){
char op=getchar();
while(!ischar(op))op=getchar();
return op;
}IL string qs(){
string op="";char u=getchar();
while(!ischar(u))u=getchar();
while(ischar(u))op+=u,u=getchar();
return op;
}IL void qw(TY x){
if(!x){putchar('0');return;}
if(x<0)putchar('-'),x=-x;
if(x>=10)qw(x/10);putchar(x%10+'0');
}IL void qw(TY x,char op){qw(x),putchar(op);}
IL void ws(string s){FOR(i,0,s.size())putchar(s[i]);}
IL TY Ceil(TY a,TY b){return a/b+(a%b!=0);}
IL TY Mod(TY a){return (a>=mod?a-mod:a);}
IL TY Abs(TY a,TY b){return a>b?a-b:b-a;}
IL TY Pow(TY a,TY b){
TY ans=1,base=a;
while(b){
if(b&1)ans=ans*base%mod;
base=base*base%mod;b>>=1;
}return ans;
}TY n,Ans,val[MAXN],st[MAXN][20],Log[MAXN],pre[MAXN],have[MAXN],bst[MAXN][20];
set<TY> lst[MAXN],id;
IL TY query(TY x,TY y){
TY k=Log[y-x+1];
return min(st[x][k],st[y-(1ll<<k)+1][k]);
}IL bool Query(TY x,TY y){
TY k=Log[y-x+1];
return (bst[x][k]&bst[y-(1ll<<k)+1][k]);
}IL void del(TY l,TY r){
set<TY>::iterator itl=id.lower_bound(l),itr=id.upper_bound(r);
for(set<TY>::iterator it=itl;it!=itr;++it)lst[val[*it]].erase(*it);
id.erase(itl,itr);
}
int main(){
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
For(i,2,500000)Log[i]=Log[i/2]+1;
/* init */
n=qr();For(i,1,n)val[i]=qr();
For(i,1,n){
bool ok=0;
if(val[i]==1)pre[i]=i,ok=1;
else{
if(lst[val[i]-1].empty())pre[i]=-1;
else pre[i]=*--lst[val[i]-1].end(),del(pre[i],i-1),ok=1;
}if(ok)lst[val[i]].insert(i);id.insert(i);
}For(i,1,n)st[i][0]=pre[i];
For(j,1,19)for(TY i=1;i+(1ll<<j)-1<=n;++i)st[i][j]=min(st[i][j-1],st[i+(1ll<<j-1)][j-1]);
For(i,1,n)have[i]=(val[i]==1||(pre[i]!=-1&&query(pre[i]+1,i)>=pre[i])),bst[i][0]=have[i];
For(j,1,19)for(TY i=1;i+(1ll<<j)-1<=n;++i)bst[i][j]=(bst[i][j-1]&bst[i+(1ll<<j-1)][j-1]);
For(i,1,n){
TY l=i,r=n,ans=i-1;
while(l<=r){
TY mid=(l+r)>>1;
if(Query(i,mid)&&query(i,mid)>=i)l=mid+1,ans=mid;
else r=mid-1;
}Ans+=ans-i+1;
}qw(Ans);
return 0;
}
提出情報
コンパイルエラー
./Main.cpp: In function ‘void qw(long long int)’:
./Main.cpp:47:2: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
47 | if(x>=10)qw(x/10);putchar(x%10+'0');
| ^~
./Main.cpp:47:20: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’
47 | if(x>=10)qw(x/10);putchar(x%10+'0');
| ^~~~~~~
./Main.cpp: In function ‘void ws(std::string)’:
./Main.cpp:23:34: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
23 | #define FOR(i,a,b) for(TY i=(a);i<(b);++i)
| ^
./Main.cpp:49:22: note: in expansion of macro ‘FOR’
49 | IL void ws(string s){FOR(i,0,s.size())putchar(s[i]);}
| ^~~
./Main.cpp: In function ‘int main()’:
./Main.cpp:86:80: warning: suggest parentheses around ‘-’ inside ‘<<’ [-Wparentheses]
86 | For(j,1,19)for(TY i=1;i+(1ll<<j)-1<=n;++i)st[i][j]=min(st[i][j-1],st[i+(1ll<<j-1)][j-1]);
| ~^~
./Main.cpp:88:80: warning: suggest parentheses around ‘-’ inside ‘<<’ [-Wparentheses]
88 | For(j,1,19)for(TY i=1;i+(1ll<<j)-1<=n;++i)bst[i][j]=(bst[i][j-1]&bst[i+(1ll<<j-1)][j-1]);
| ~^~
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
600 / 600 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt |
| All |
01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt, 02_rand_1_01.txt, 02_rand_1_02.txt, 02_rand_1_03.txt, 02_rand_1_04.txt, 02_rand_1_05.txt, 02_rand_1_06.txt, 02_rand_1_07.txt, 02_rand_1_08.txt, 02_rand_1_09.txt, 02_rand_1_10.txt, 02_rand_1_11.txt, 02_rand_1_12.txt, 02_rand_1_13.txt, 02_rand_1_14.txt, 02_rand_1_15.txt, 03_rand_2_01.txt, 03_rand_2_02.txt, 03_rand_2_03.txt, 03_rand_2_04.txt, 03_rand_2_05.txt, 03_rand_2_06.txt, 03_rand_2_07.txt, 03_rand_2_08.txt, 03_rand_2_09.txt, 03_rand_2_10.txt, 03_rand_2_11.txt, 03_rand_2_12.txt, 03_rand_2_13.txt, 03_rand_2_14.txt, 03_rand_2_15.txt, 03_rand_2_16.txt, 03_rand_2_17.txt, 03_rand_2_18.txt, 03_rand_2_19.txt, 03_rand_2_20.txt, 03_rand_2_21.txt, 03_rand_2_22.txt, 03_rand_2_23.txt, 03_rand_2_24.txt, 03_rand_2_25.txt, 03_rand_2_26.txt, 03_rand_2_27.txt, 03_rand_2_28.txt, 03_rand_2_29.txt, 03_rand_2_30.txt, 03_rand_2_31.txt, 03_rand_2_32.txt, 03_rand_2_33.txt, 03_rand_2_34.txt, 03_rand_2_35.txt, 03_rand_2_36.txt, 03_rand_2_37.txt, 03_rand_2_38.txt, 03_rand_2_39.txt, 03_rand_2_40.txt, 03_rand_2_41.txt, 03_rand_2_42.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| 01_sample_01.txt |
AC |
25 ms |
30888 KiB |
| 01_sample_02.txt |
AC |
23 ms |
30920 KiB |
| 01_sample_03.txt |
AC |
25 ms |
30748 KiB |
| 02_rand_1_01.txt |
AC |
25 ms |
30900 KiB |
| 02_rand_1_02.txt |
AC |
29 ms |
30896 KiB |
| 02_rand_1_03.txt |
AC |
596 ms |
245720 KiB |
| 02_rand_1_04.txt |
AC |
602 ms |
245576 KiB |
| 02_rand_1_05.txt |
AC |
28 ms |
30916 KiB |
| 02_rand_1_06.txt |
AC |
502 ms |
199136 KiB |
| 02_rand_1_07.txt |
AC |
496 ms |
199056 KiB |
| 02_rand_1_08.txt |
AC |
506 ms |
203584 KiB |
| 02_rand_1_09.txt |
AC |
497 ms |
203404 KiB |
| 02_rand_1_10.txt |
AC |
451 ms |
203212 KiB |
| 02_rand_1_11.txt |
AC |
459 ms |
203176 KiB |
| 02_rand_1_12.txt |
AC |
427 ms |
200900 KiB |
| 02_rand_1_13.txt |
AC |
419 ms |
200816 KiB |
| 02_rand_1_14.txt |
AC |
387 ms |
199076 KiB |
| 02_rand_1_15.txt |
AC |
392 ms |
199056 KiB |
| 03_rand_2_01.txt |
AC |
638 ms |
225848 KiB |
| 03_rand_2_02.txt |
AC |
640 ms |
225736 KiB |
| 03_rand_2_03.txt |
AC |
646 ms |
225752 KiB |
| 03_rand_2_04.txt |
AC |
648 ms |
225588 KiB |
| 03_rand_2_05.txt |
AC |
645 ms |
225808 KiB |
| 03_rand_2_06.txt |
AC |
665 ms |
225744 KiB |
| 03_rand_2_07.txt |
AC |
657 ms |
225788 KiB |
| 03_rand_2_08.txt |
AC |
660 ms |
213820 KiB |
| 03_rand_2_09.txt |
AC |
658 ms |
213832 KiB |
| 03_rand_2_10.txt |
AC |
657 ms |
214096 KiB |
| 03_rand_2_11.txt |
AC |
654 ms |
213788 KiB |
| 03_rand_2_12.txt |
AC |
646 ms |
213856 KiB |
| 03_rand_2_13.txt |
AC |
652 ms |
213928 KiB |
| 03_rand_2_14.txt |
AC |
644 ms |
213988 KiB |
| 03_rand_2_15.txt |
AC |
614 ms |
207324 KiB |
| 03_rand_2_16.txt |
AC |
609 ms |
207328 KiB |
| 03_rand_2_17.txt |
AC |
612 ms |
207352 KiB |
| 03_rand_2_18.txt |
AC |
617 ms |
207300 KiB |
| 03_rand_2_19.txt |
AC |
601 ms |
207160 KiB |
| 03_rand_2_20.txt |
AC |
627 ms |
207364 KiB |
| 03_rand_2_21.txt |
AC |
602 ms |
207432 KiB |
| 03_rand_2_22.txt |
AC |
492 ms |
199212 KiB |
| 03_rand_2_23.txt |
AC |
478 ms |
199184 KiB |
| 03_rand_2_24.txt |
AC |
482 ms |
199132 KiB |
| 03_rand_2_25.txt |
AC |
486 ms |
198984 KiB |
| 03_rand_2_26.txt |
AC |
472 ms |
198988 KiB |
| 03_rand_2_27.txt |
AC |
488 ms |
199060 KiB |
| 03_rand_2_28.txt |
AC |
490 ms |
199204 KiB |
| 03_rand_2_29.txt |
AC |
413 ms |
198744 KiB |
| 03_rand_2_30.txt |
AC |
421 ms |
198744 KiB |
| 03_rand_2_31.txt |
AC |
431 ms |
198744 KiB |
| 03_rand_2_32.txt |
AC |
421 ms |
198852 KiB |
| 03_rand_2_33.txt |
AC |
410 ms |
198824 KiB |
| 03_rand_2_34.txt |
AC |
420 ms |
198912 KiB |
| 03_rand_2_35.txt |
AC |
425 ms |
198744 KiB |
| 03_rand_2_36.txt |
AC |
406 ms |
198868 KiB |
| 03_rand_2_37.txt |
AC |
418 ms |
198740 KiB |
| 03_rand_2_38.txt |
AC |
420 ms |
198744 KiB |
| 03_rand_2_39.txt |
AC |
423 ms |
198676 KiB |
| 03_rand_2_40.txt |
AC |
426 ms |
198700 KiB |
| 03_rand_2_41.txt |
AC |
425 ms |
198852 KiB |
| 03_rand_2_42.txt |
AC |
423 ms |
198868 KiB |