# 2019.8.23 小结

T1 数列 40/0

#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
int n,a[60],s[60];
long long ans;
void dfs(int x){
if(x>n+1) return;
if(x==n+1){
ans++;
ans=ans%mod;
return;
}
int l=-1,r=mod;
if(x>=3){
for(int i=1;i<=x-2;++i){
if(s[i]>=s[x-1]){
r=min(r,s[i]);
}
if(s[i]<=s[x-1]){
l=max(l,s[i]);
}
}
}
for(int i=max(1,l);i<=min(a[x],r);++i){//就这写错了
s[x]=i;
dfs(x+1);
}
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;++i){
scanf("%d",&a[i]);
}
dfs(1);
printf("%lld",ans%mod);
return 0;
}


T2 加法 0/0

#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int T;
int n,m,k,a,s[N];
int c[N];
struct node{
int l,r;
}t[N];
bool cmp(node x,node y){
return x.l!=y.l ? x.l<y.l : x.r>y.r;
}
int lowbit(int x){
return x&(-x);
}
int ans=0;
for(;x;x-=lowbit(x)) ans+=c[x];
return ans;
}
for(;x<=n;x+=lowbit(x)) c[x]+=y;
}
bool book(int x){
memset(c,0,sizeof(c));
priority_queue<int> q;
int now=1,sum=0;
for(int i=1;i<=n;++i){
while(!q.empty()&&q.top()<i) q.pop();
while(now<=m&&t[now].l<=i){
if(t[now].r>=i) q.push(t[now].r);
now++;
}
if(sum+tmp>k) return 0;
sum+=tmp;
while(tmp--){
if(!q.empty() && q.top()>=i){
}else return 0;
}
}
return 1;
}
int main(){
scanf("%d",&T);
while(T--){
scanf("%d %d %d %d",&n,&m,&k,&a);
int minn=1<<30;
for(int i=1;i<=n;++i) scanf("%d",&s[i]),minn=min(minn,s[i]);
for(int i=1;i<=m;++i){
scanf("%d %d",&t[i].l,&t[i].r);
if(t[i].l>t[i].r) swap(t[i].l,t[i].r);
}
sort(t+1,t+1+m,cmp);
int l=minn,r=minn+k*a;
while(l<=r){
int mid=(l+r)>>1;
if(book(mid)) l=mid+1;
else r=mid-1;
}
printf("%d\n",r);
}
return 0;
}


T3 颜色 100/100

#include<bits/stdc++.h>
#include<ctime>
using namespace std;
const long long mod=1e9+7;
const int N=3e5+10;
long long num[N];
int T,n,a[N],f[2]={1,-1},k;
map<long long,long long> book;
vector <int> p[N];
int main(){
freopen("color.in","r",stdin);
freopen("color.out","w",stdout);
srand((unsigned)time(0));
scanf("%d",&T);
while(T--){
scanf("%d",&n);
for(int i=1;i<=n;++i){
scanf("%d",&a[i]);
p[a[i]].push_back(i);
}
for(int i=1;i<=n;++i){
if(p[i].size()==0) continue;
else if(p[i].size()==1) num[p[i][0]]=0;
else{
for(int j=0;j<p[i].size()-1;++j){
k=rand()&1;
x=(rand()*rand()%mod*rand()%mod*rand()%mod)%mod*f[k];
num[p[i][j]]=x;
}
}
}
for(int i=1;i<=n;++i){