The Data Group supports the change and check between zones. If you haven't finished it for a long time, you will soon forget it. The two points you should pay attention to during the preparation are: 1. Before creating a data set, it may cause an int attack. 2. Use % d to enter long. Even if the incoming data security certificate is smaller than 10 ^ 9, the problem may occur.
Remember differential data group A [I] = num [I]-num [I-1];
Sum [I] = sum [1] + sum [2] +... + sum [N]
= A1 + A1 + A2 + A1 + A2 + A3 +... + A1 + A2 +... +
= N * A1 + (n-1) * A2 +... + 1 *
= (N + 1) * (A1 + A2 +... + an)-1 * a1-2 * A2-...-(n) *
Separate processing of segma (AI) and segma (ai * I)
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<ctime>#include<cmath>#include<algorithm>#include<set>#include<map>#include<vector>#include<string>#include<queue>using namespace std;#ifdef WIN32#define LL "%I64d"#else#define LL "%lld"#endif#define MAXN 110000#define MAXV MAXN*2#define MAXE MAXV*2#define INF 0x3f3f3f3f#define INFL 0x3f3f3f3f3f3f3f3fLLtypedef long long qword;inline int nextInt(){ char ch; int x=0; bool flag=false; do ch=getchar(),flag=(ch==‘-‘)?true:flag; while(ch<‘0‘||ch>‘9‘); do x=x*10+ch-‘0‘; while (ch=getchar(),ch<=‘9‘ && ch>=‘0‘); return x*(flag?-1:1);}int n,m;struct Edge{ int np; Edge *next;}E[MAXE],*V[MAXV];int tope=-1;void addedge(int x,int y){ E[++tope].np=y; E[tope].next=V[x]; V[x]=&E[tope];}struct aaa{ int val,id;};bool operator <(aaa a1,aaa a2){ return a1.val<a2.val;}multiset<aaa>S;int ptr[MAXN][2];int num[MAXN];int gp[MAXN];bool vis[MAXN];bool vis2[MAXN];bool dfs(int now,int g){ if (now==-1)return true; if (vis2[now]) { return gp[now]==g; } gp[now]=g; if (ptr[now][g]==-1)return false; vis[now]=vis2[now]=true; bool t=dfs(ptr[now][1-g],g) && dfs(ptr[now][g],g); vis2[now]=false; return t;}int main(){ freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); int i,j,k; int x,y,z; int a,b; scanf("%d%d%d",&n,&a,&b); aaa at; for (i=0;i<n;i++) { scanf("%d",&x); num[i]=x; at.val=x; at.id=i; S.insert(at); } multiset<aaa>::iterator it1; memset(ptr,-1,sizeof(ptr)); for (i=0;i<n;i++) { at.val=a-num[i]; it1=S.find(at); if (it1!=S.end()) { ptr[i][0]=it1->id; } at.val=b-num[i]; it1=S.find(at); if (it1!=S.end()) { ptr[i][1]=it1->id; } } for (i=0;i<n;i++) { if (vis[i])continue; if (!dfs(i,0)) { if (!dfs(i,1)) { printf("NO\n"); return 0; } } } printf("YES\n"); for (i=0;i<n;i++) { printf("%d ",gp[i]); } return 0;}
Customized Data Group Operation Template