Submission #57300368


Source Code Expand

#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define int long long
using namespace std;
// using namespace  __gnu_pbds;
// tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> tr;//从小到大
// int findnum(int k){auto it=tr.find_by_order(k-1);return ((it!=tr.end())?(*it):1e9+7);}//查元素
// int findrank(int x){return tr.order_of_key(x)+1;}//查排名
// static char buf[100000],*pa=buf,*pd=buf;
// #define gc pa==pd&&(pd=(pa=buf)+fread(buf,1,100000,stdin),pa==pd)?EOF:*pa++ 
inline int read()
{
	int w = 1, s = 0; char ch = getchar();
	while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}
	while(isdigit(ch)){s=s*10+(ch-'0');ch=getchar();}
	return w*s;
}
const int mod=998244353;
const int maxn=1e6+10;
const int inf=1e9+7;
int n,ans,a[maxn],b[maxn];
int pre[maxn];
signed main()
{
#ifdef Lydic
    freopen(".in","r",stdin);
    freopen(".out","w",stdout);
#endif
    cin>>n;
	pre[1]=1;
	for(int i=2;i<=1e6;i++)pre[i]=pre[i-1]+i;
	for(int i=1;i<=n;i++)a[i]=read();
	for(int i=1;i<=n;i++)b[i]=a[i]-a[i-1];
	int l=1,r=1,num=1,sum=0,cha=a[2]-a[1];
	for(int i=2;i<=n;i++)
	{
		if(a[i]-a[i-1]==cha)r++;
		else
		{
			sum++;
			num=r-l+1;
			ans=ans+pre[num];
			l=i-1;
			r=i;
			cha=a[i]-a[i-1];
		}
	}
	num=r-l+1;ans+=pre[num];

	cout<<ans-sum;
    return 0;
}

Submission Info

Submission Time
Task C - Count Arithmetic Subarrays
User Lydic
Language C++ 20 (gcc 12.2)
Score 300
Code Size 1401 Byte
Status AC
Exec Time 12 ms
Memory 14472 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 21
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_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 02_random2_05.txt, 02_random2_06.txt, 02_random2_07.txt, 02_random2_08.txt, 02_random2_09.txt, 02_random2_10.txt, 03_handmade_00.txt, 03_handmade_01.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 4 ms 11416 KiB
00_sample_01.txt AC 4 ms 11344 KiB
00_sample_02.txt AC 4 ms 11304 KiB
01_random_00.txt AC 4 ms 11476 KiB
01_random_01.txt AC 4 ms 11484 KiB
01_random_02.txt AC 7 ms 12632 KiB
01_random_03.txt AC 10 ms 13520 KiB
01_random_04.txt AC 8 ms 12968 KiB
02_random2_00.txt AC 11 ms 14416 KiB
02_random2_01.txt AC 11 ms 14468 KiB
02_random2_02.txt AC 11 ms 14472 KiB
02_random2_03.txt AC 11 ms 14392 KiB
02_random2_04.txt AC 12 ms 14392 KiB
02_random2_05.txt AC 12 ms 14392 KiB
02_random2_06.txt AC 12 ms 14416 KiB
02_random2_07.txt AC 12 ms 14424 KiB
02_random2_08.txt AC 12 ms 14420 KiB
02_random2_09.txt AC 12 ms 14352 KiB
02_random2_10.txt AC 11 ms 14352 KiB
03_handmade_00.txt AC 4 ms 11300 KiB
03_handmade_01.txt AC 12 ms 14428 KiB