9.29 正睿提高6
2018.9.29 正睿提高6
时间:3.5h(实际)
期望得分:100+30+1
实际得分:100+20+0
T3想了一个半小时1分也没有TAT
printf神奇的返回值。。
A
//容斥一下就好了
#include <cstdio>
#include <cctype>
#include <algorithm>
//#define gc() getchar()
#define MAXIN 200000
#define gc() (SS==TT&&(TT=(SS=IN)+fread(IN,1,MAXIN,stdin),SS==TT)?EOF:*SS++)
typedef long long LL;
const int N=1e5+5;
int ref[N],A[N],pres[N],preb[N],sufs[N],sufb[N],cnt1[N],cnt2[N];
char IN[MAXIN],*SS=IN,*TT=IN;
struct BIT
{
#define lb(x) (x&-x)
int n,t[N];
inline void Add(int p)
{
for(; p<=n; p+=lb(p)) ++t[p];
}
inline int Query(int p)
{
int res=0;
for(; p; p^=lb(p)) res+=t[p];
return res;
}
}tpre,tsuf;
inline int read()
{
int now=0;register char c=gc();
for(;!isdigit(c);c=gc());
for(;isdigit(c);now=now*10+c-'0',c=gc());
return now;
}
inline int Find(int x,int r)
{
int l=1,mid;
while(l<r)
if(ref[mid=l+r>>1]<x) l=mid+1;
else r=mid;
return l;
}
int main()
{
// freopen("ex_a3.in","r",stdin);
// freopen(".out","w",stdout);
int n=read();
for(int i=1; i<=n; ++i) ref[i]=A[i]=read();
std::sort(ref+1,ref+1+n); int cnt=1;
for(int i=2; i<=n; ++i) if(ref[i]!=ref[i-1]) ref[++cnt]=ref[i];
for(int i=1; i<=n; ++i) A[i]=Find(A[i],cnt);
tpre.n=tsuf.n=cnt;
for(int i=1; i<=n; ++i)
pres[i]=tpre.Query(A[i]-1), preb[i]=i-1-pres[i]-cnt1[A[i]], tpre.Add(A[i]), ++cnt1[A[i]];
for(int i=n; i; --i)
sufs[i]=tsuf.Query(A[i]-1), sufb[i]=n-i-sufs[i]-cnt2[A[i]], tsuf.Add(A[i]), ++cnt2[A[i]];
LL s1=0,s2=0;
for(int i=1; i<=n; ++i) s1+=sufb[i], s2+=sufs[i];
LL ans=s1*s2;
for(int i=1; i<=n; ++i) ans-=1ll*sufs[i]*sufb[i];//a=c
for(int i=1; i<=n; ++i) ans-=1ll*preb[i]*sufb[i];//a=d
for(int i=1; i<=n; ++i) ans-=1ll*pres[i]*sufs[i];//b=c
for(int i=1; i<=n; ++i) ans-=1ll*pres[i]*preb[i];//b=d
printf("%lld\n",ans);
return 0;
}
B
C
考试代码
B
#include <cstdio>
#include <cstring>
#include <algorithm>
#define mod 990804011
#define Mod(x) (x>=mod&&(x-=mod))
typedef long long LL;
const int N=55,M=25;
int n,Ans,len[N];
char s[N][M];
void DFS(int x,int y)
{
if(x>=2 && y>len[x])
{
for(int j=1; j<=len[x-1]; ++j)
if(j>len[x]) return;
else if(s[x-1][j]>s[x][j]) return;
else if(s[x-1][j]<s[x][j]) break;
else if(j==len[x]) return;
}
if(y>len[x]) ++x, y=1;
if(x>n)
{
++Ans;
return;
}
while(y<=len[x] && s[x][y]!='?') ++y;
if(y<=len[x] && s[x][y]=='?')
{
for(int i=0; i<26; ++i)
s[x][y]=i+'a', DFS(x,y+1), s[x][y]='?';
}
else DFS(x,y);
}
void Spec1()
{
static int f[N][30][30];
f[0][0][0]=1;
len[n+1]=2, s[n+1][1]=s[n+1][2]='z'+1;
for(int i=1; i<=n+1; ++i)
{
if(len[i]==1)
{
if(s[i][1]=='?')
for(int a=1; a<=26; ++a)
for(int b=0; b<a; ++b)
f[i][a][0]+=f[i-1][b][0], Mod(f[i][a][0]);
else
for(int a=0,t=s[i][1]-'a'+1; a<t; ++a)
f[i][t][0]+=f[i-1][a][0], Mod(f[i][t][0]);
}
else
{
if(s[i][1]=='?')
{
if(s[i][2]=='?')
{
for(int a=1; a<=26; ++a)
for(int b=1; b<=26; ++b)
{
for(int c=0; c<a; ++c)
for(int d=0; d<=26; ++d)
f[i][a][b]+=f[i-1][c][d], Mod(f[i][a][b]);
for(int d=0; d<b; ++d)
f[i][a][b]+=f[i-1][a][d], Mod(f[i][a][b]);
}
}
else
{
int t=s[i][2]-'a'+1;
for(int a=1; a<=26; ++a)
{
for(int c=0; c<a; ++c)
for(int d=0; d<=26; ++d)
f[i][a][t]+=f[i-1][c][d], Mod(f[i][a][t]);
for(int d=0; d<t; ++d)
f[i][a][t]+=f[i-1][a][d], Mod(f[i][a][t]);
}
}
}
else
{
int t1=s[i][1]-'a'+1;
if(s[i][2]=='?')
{
for(int c=0; c<t1; ++c)
for(int b=1; b<=26; ++b)
for(int d=0; d<=26; ++d)
f[i][t1][b]+=f[i-1][c][d], Mod(f[i][t1][b]);
for(int b=1; b<=26; ++b)
for(int d=0; d<b; ++d)
f[i][t1][b]+=f[i-1][t1][d], Mod(f[i][t1][b]);
}
else
{
int t2=s[i][2]-'a'+1;
for(int c=0; c<t1; ++c)
for(int d=0; d<=26; ++d)
f[i][t1][t2]+=f[i-1][c][d], Mod(f[i][t1][t2]);
for(int d=0; d<t2; ++d)
f[i][t1][t2]+=f[i-1][t1][d], Mod(f[i][t1][t2]);
}
}
}
}
printf("%d\n",(int)(f[n+1][27][27]%mod));
}
int main()
{
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
scanf("%d",&n); int mx=0;
for(int i=1; i<=n; ++i)
scanf("%s",s[i]+1), mx=std::max(mx,len[i]=strlen(s[i]+1));
// for(int i=1; i<n; ++i) if(len[i]>len[i+1]) return putchar('0'),0;//字典序是什么。。
if(mx<=2) {Spec1(); return 0;}
if(n*mx<=10)
{
Ans=0, DFS(1,1), printf("%d\n",Ans);
return 0;
}
putchar('1');
return 0;
}
C
#include <cstdio>
#include <algorithm>
#define mod 990804011
typedef long long LL;
const int N=18;
LL L[N],R[N];
void Work()
{
int K; scanf("%d",&K);
for(int i=1; i<=K; ++i) scanf("%lld%lld",&L[i],&R[i]);
if(K==1) {printf("%lld\n",(R[1]-L[1]+1-(!L[1])))%mod; return;}
}
int main()
{
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
int T; scanf("%d",&T);
while(T--) Work();
return 0;
}
------------------------------------------------------------------------------------------------------------------------
很久以前的奇怪但现在依旧成立的签名
attack is our red sun $$\color{red}{\boxed{\color{red}{attack\ is\ our\ red\ sun}}}$$ ------------------------------------------------------------------------------------------------------------------------
很久以前的奇怪但现在依旧成立的签名
attack is our red sun $$\color{red}{\boxed{\color{red}{attack\ is\ our\ red\ sun}}}$$ ------------------------------------------------------------------------------------------------------------------------