标签:algo name 区间 sed one bool fine algorithm close
题目大意就是问能分出几个使三个区间的和相等的分发
1 #include <algorithm> 2 #include <stack> 3 #include <istream> 4 #include <stdio.h> 5 #include <map> 6 #include <math.h> 7 #include <vector> 8 #include <iostream> 9 #include <queue> 10 #include <string.h> 11 #include <set> 12 #include <cstdio> 13 #define FR(i,n) for(int i=0;i<n;i++) 14 #define MAX 2005 15 #define mkp pair <int,int> 16 using namespace std; 17 #include <bits/stdc++.h> 18 const int maxn = 5e5 + 40; 19 typedef long long ll; 20 const int inf = 0x3fffff; 21 void read(ll &x) { 22 char ch; bool flag = 0; 23 for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == ‘-‘)) || 1); ch = getchar()); 24 for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48, ch = getchar()); 25 x *= 1 - 2 * flag; 26 } 27 28 29 ll n; 30 ll sum[maxn],arr[maxn]; 31 ll val[maxn]; 32 ll s2[maxn]; 33 ll l[maxn]; 34 int main() { 35 read(n); 36 for(int i=0;i<n;i++)read(val[i]); 37 sum[0]=val[0]; 38 for(int i=1;i<n;i++)sum[i]+=sum[i-1]+val[i]; 39 //int i = 0,j = n-1; 40 for(int i=n-1;i>=0;i--)s2[i]+=s2[i+1]+val[i]; 41 if(sum[n-1]%3)return 0*printf("%d\n",0); 42 ll temp = 0; 43 for(int i=0;i<n;i++){ l[i]=temp; 44 if(sum[i]==sum[n-1]/3)temp++; 45 46 } 47 ll ans = 0; 48 for(int i=n-1;i>=1;i--){ 49 if(s2[i]==sum[n-1]/3){ 50 ans+=l[i-1]; 51 } 52 // cout<<ans<<endl; 53 } 54 cout<<ans<<endl; 55 return 0; 56 }
标签:algo name 区间 sed one bool fine algorithm close
原文地址:https://www.cnblogs.com/DreamKill/p/9434182.html