Submission #62094940
Source Code Expand
Copy
#include<bits/stdc++.h>#define int long long#define f(i,j,n) for(int i=j;i<=n;i++)#define F(i,n,j) for(int i=n;i>=j;i--)#define updmax(a,b) a=max(a,b)#define updmin(a,b) a=min(a,b)#define pb push_back#define XQZusing namespace std;namespace fsd{#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,MAXSIZE,stdin),p1==p2)?EOF:*p1++)const int MAXSIZE=1<<20;char buf[MAXSIZE],*p1,*p2;inline int read(){int ak=0,ioi=1;char c=gc();while(!isdigit(c)){if(c=='-')ioi=-1;c=gc();}while(isdigit(c))ak=ak*10+(c^48),c=gc();return ak*ioi;}inline string reads(){string o="";
#include<bits/stdc++.h> #define int long long #define f(i,j,n) for(int i=j;i<=n;i++) #define F(i,n,j) for(int i=n;i>=j;i--) #define updmax(a,b) a=max(a,b) #define updmin(a,b) a=min(a,b) #define pb push_back #define XQZ using namespace std; namespace fsd{ #define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,MAXSIZE,stdin),p1==p2)?EOF:*p1++) const int MAXSIZE=1<<20; char buf[MAXSIZE],*p1,*p2; inline int read(){ int ak=0,ioi=1;char c=gc(); while(!isdigit(c)){if(c=='-')ioi=-1;c=gc();} while(isdigit(c))ak=ak*10+(c^48),c=gc(); return ak*ioi; } inline string reads(){ string o=""; char p=gc(); while(p>'z'||p<'a'){p=gc();} while(p<='z'&&p>='a'){o+=p;p=gc();} return o; } inline char readc(){ char p=gc(); while(!((p<='z'&&p>='a')||(p<='Z'&&p>='A'))){p=gc();} return p; } inline long double readd(){ long double ak=0;int ioi=1;char c=gc(); while(!isdigit(c)){if(c=='-')ioi=-1;c=gc();} while(isdigit(c))ak*=10,ak+=c-'0',c=gc(); c=gc(); long double q=0.1; while(isdigit(c))ak+=(c-'0')*q,q*=0.1,c=gc(); return ak*ioi; } } using namespace fsd; int n; int ls[300010]; int a[300010]; void gs(){ n=read(); f(i,1,n)a[i]=read(); int ans=0; f(i,1,n){ int t=ls[a[i]+1],s=ls[a[i]-1],q=ls[a[i]]; if(q<s&&q<t){ ans+=((i-max(s,t))-(min(s,t)-q))*(n-i+1); }else{ ans+=(i-max(s,max(t,q)))*(n-i+1); } ls[a[i]]=i; } printf("%lld\n",ans); } signed main(){ #ifndef XQZ freopen(".in","r",stdin); freopen(".out","w",stdout); #endif #ifdef NXD int t=0;cin>>t;while(t--) #endif gs(); return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Double Sum 3 |
User | xiangqizhen |
Language | C++ 17 (Clang 16.0.6) |
Score | 525 |
Code Size | 1607 Byte |
Status | AC |
Exec Time | 9 ms |
Memory | 9500 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 525 / 525 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 02_permutation_00.txt, 02_permutation_01.txt, 02_permutation_02.txt, 02_permutation_03.txt, 02_permutation_04.txt, 02_permutation_05.txt, 02_permutation_06.txt, 02_permutation_07.txt, 02_permutation_08.txt, 02_permutation_09.txt, 02_permutation_10.txt, 02_permutation_11.txt, 03_random_00.txt, 03_random_01.txt, 03_random_02.txt, 03_random_03.txt, 03_random_04.txt, 03_random_05.txt, 03_random_06.txt, 03_random_07.txt, 03_random_08.txt, 03_random_09.txt, 03_random_10.txt, 03_random_11.txt, 03_random_12.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_sample_00.txt | AC | 1 ms | 3748 KB |
00_sample_01.txt | AC | 1 ms | 3644 KB |
00_sample_02.txt | AC | 1 ms | 3680 KB |
01_handmade_00.txt | AC | 1 ms | 3680 KB |
01_handmade_01.txt | AC | 5 ms | 7112 KB |
01_handmade_02.txt | AC | 6 ms | 9496 KB |
02_permutation_00.txt | AC | 3 ms | 5544 KB |
02_permutation_01.txt | AC | 3 ms | 6276 KB |
02_permutation_02.txt | AC | 8 ms | 9284 KB |
02_permutation_03.txt | AC | 7 ms | 8776 KB |
02_permutation_04.txt | AC | 7 ms | 8980 KB |
02_permutation_05.txt | AC | 8 ms | 9336 KB |
02_permutation_06.txt | AC | 8 ms | 9456 KB |
02_permutation_07.txt | AC | 8 ms | 9276 KB |
02_permutation_08.txt | AC | 8 ms | 9500 KB |
02_permutation_09.txt | AC | 8 ms | 9436 KB |
02_permutation_10.txt | AC | 6 ms | 9336 KB |
02_permutation_11.txt | AC | 5 ms | 9344 KB |
03_random_00.txt | AC | 2 ms | 4652 KB |
03_random_01.txt | AC | 2 ms | 4992 KB |
03_random_02.txt | AC | 5 ms | 7056 KB |
03_random_03.txt | AC | 2 ms | 4856 KB |
03_random_04.txt | AC | 3 ms | 5832 KB |
03_random_05.txt | AC | 9 ms | 9500 KB |
03_random_06.txt | AC | 9 ms | 9280 KB |
03_random_07.txt | AC | 8 ms | 9276 KB |
03_random_08.txt | AC | 8 ms | 9380 KB |
03_random_09.txt | AC | 8 ms | 9384 KB |
03_random_10.txt | AC | 2 ms | 4380 KB |
03_random_11.txt | AC | 3 ms | 5360 KB |
03_random_12.txt | AC | 3 ms | 5224 KB |