**错误积累&&防止GG写法总结

19.3.20 关于int与ll

1.如果一道题时间充足,把全部变量定义成long long

2.特别注意最上面宏定义的变量类型,特别是FOR

3.如果是int,用1LL* ......

**实例,让我崩溃

1 #include<bits/stdc++.h>
2 using namespace std;
3 #define rg register
4 typedef long long ll;
5 #define gmax(a,b) a=max(a,b)
6 #define gmin(a,b) a=min(a,b)
View Code
1 #define FOR(i,a,b) for(rg int i=a;i<=b;++i)
2 #define For(i,a,b) for(rg int i=a;i>=b;--i)
 1 #define gc pa==pb&&(pb=(pa=buf)+fread(buf,1,100000,stdin),pa==pb)?EOF:*pa++
 2 static char buf[100000],*pa(buf),*pb(buf);
 3 inline int rd()
 4 {
 5     rg int x(0),w(1);
 6     rg char c(gc);
 7     while(c<'0' || c>'9')
 8     {
 9         if(c=='-') w=-1;
10         c=gc;
11     }
12     while(c>='0' && c<='9') x=x*10+c-48,c=gc;
13     return x*w;
14 }
15 
16 const int N=1000005;
17 const ll MOD=998244353,ny=499122177;
18 ll f[N],g[N],tn[N],jc[N];
19 int c[N],a[N],n;
20 ll ans;
21 
22 void add(int x,int y)
23 {
24     for(;x<=n;x+=x&(-x)) c[x]+=y;
25 }
26 
27 ll ask(int x)
28 {
29     ll res=0;
30     for(;x;x-=x&(-x)) res+=c[x];
31     return res;
32 }
33 
34 int main()
35 {
36     freopen("sort.in","r",stdin);
37     freopen("sort.out","w",stdout);
38     n=rd();FOR(i,1,n) a[i]=rd();
39     jc[0]=1;FOR(i,1,n) jc[i]=(i*jc[i-1])%MOD;
View Code
1 FOR(i,2,n) f[i]=((i*f[i-1])%MOD+(1LL*i*(i-1)/2)%MOD*jc[i-1]%MOD)%MOD;
1     tn[1]=1;add(a[n],1);
2     FOR(i,2,n)
3         g[i]=ask(a[n-i+1]),add(a[n-i+1],1),
4         tn[i]=((g[i]*jc[i-1])%MOD+tn[i-1])%MOD;
5     FOR(i,1,n) ans=(ans+g[i]*f[i-1]%MOD+g[i]*(g[i]-1)%MOD*ny%MOD*jc[i-1]%MOD+g[i]*tn[i-1]%MOD)%MOD;
6     cout<<ans;
7     return 0;
8 }
View Code

 

 

21.10.26

队列是while(head < tail)

不是小于等于!!!!!

while ( hd < tl )
 1     {
 2         ++hd;
 3         xx=l[hd][0];yy=l[hd][1];
 4         FOR(i,0,7)
 5         {
 6             xp=xx+dx[i];yp=yy+dy[i];
 7             if((xp>=1)&&(xp<=n)&&(yp>=1)&&(yp<=m)&&(a[xp][yp]==-1))
 8             {
 9                 a[xp][yp]=a[xx][yy]+1;
10                 ++tl;l[tl][0]=xp;l[tl][1]=yp;
11             }
12         } 
13     }
View Code

 

 

21.11.15

要注意防止while()大括号内可能出现不操作的情况造成死循环

while(len>1) 
    if(x[len]==0) --len;

 

posted @ 2019-03-20 16:17  universeplayer  阅读(357)  评论(0编辑  收藏  举报