# 1004

## 代码

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <math.h>
using namespace std;
const int N = 1005;
typedef long long ll;
const int maxn = 1e6 + 5;
ll bas[65], cnt;
//int a[maxn];
int q[maxn];
//map<int, int> vis;
vector<int> vec;
char stack[maxn];
char s[maxn];
int a[maxn], dp[maxn];
ll ksm(ll a, ll b, ll mod)
{
ll res = 1;
while (b)
{
if (b & 1)
res = (res * (a % mod)) % mod;
a = ((a % mod) * (a % mod)) % mod;
b >>= 1;
}
return res;
}
int main()
{
ll t;
cin >> t;
while (t--)
{
ll n;
cin >> n;
if (n == 1)
{
cout << 26ll << endl;
}
else if (n == 2)
{
cout << 676ll << endl;
}
else if (n == 3)
{
cout << 26 * 26 * 26 << endl;
}
else
{
cout<<26*25*24<<endl;
}
}
}



# 1005

## 代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000009;
const int INVS5 = 276601605; // 1/sqrt(5)
const int A = 691504013;
const int B = 308495997;
const int maxn = 100010;
int base, last;

int qpow(int x, int y)
{
int ans = 1;
while (y)
{
if (y & 1)
ans = (ll)x * ans % MOD;
x = (ll)x * x % MOD;
y >>= 1;
}
return ans;
}

int fac[maxn], invf[maxn], a[maxn], b[maxn];

void init(int n)
{
fac[0] = a[0] = b[0] = 1;

for (int i = 1; i <= n; i++)
{
fac[i] = (ll)fac[i - 1] * i % MOD;
a[i] = (ll)a[i - 1] * A % MOD;
b[i] = (ll)b[i - 1] * B % MOD;
}
invf[n] = qpow(fac[n], MOD - 2);
for (int i = n - 1; i >= 0; i--)
invf[i] = (ll)invf[i + 1] * (i + 1) % MOD;
}

inline int C(int n, int m){ // n >= m >= 0
return n < m || m < 0 ? 0 : (ll)fac[n] * invf[m] % MOD * invf[n - m] % MOD;
}
int solve(ll n, ll c, int k)
{
int ans = 0;
for (int i = 0; i <= k; i++)
{
int tr=last,q;
last = (ll)last * base % MOD;
if (tr == 1)
q = n % MOD;
else
q = (ll)tr * (qpow(tr, n % (MOD - 1)) - 1) % MOD * qpow(tr - 1, MOD - 2) % MOD;
int res = (ll)C(k, i) * q % MOD;
if (i & 1)
ans -= res;
else
ans += res;
ans %= MOD;
}
ans = (ll)ans * qpow(INVS5, k) % MOD;
ans = (ans + MOD) % MOD;
return ans;
}

int t, k;
ll n, c;
int main()
{
init(100000);
scanf("%d", &t);
while (t--)
{
scanf("%lld%lld%d", &n, &c, &k);
base = (ll)qpow(B, c % (MOD - 1)) * qpow(qpow(A, c % (MOD - 1)), MOD - 2) % MOD;
last = qpow(a[k], c % (MOD - 1));
printf("%d\n", solve(n, c, k));
}
return 0;
}


# 1006

## 题意

1.讲第u个点的权值修改为x
2.查询与第u个点的相邻点集的MEX。

## 思路

Ps：为了防止炸内存，bit要是用vector。

## 代码

#include<bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define int long long
using namespace std;
const int N = 3e5 + 10 ;
struct Edge{
int nex , to;
}edge[N << 1];
void add_edge(int u , int v)
{
edge[TOT].to = v;
}
vector<int>tree[N] , cnt[N] , vec[N];
int n , m , q , sq;
int a[N] , du[N] , zero[N] , vis[N];
int lowbit(int x)
{
return x & (-x);
}
void add(int pos , int x , int id)
{
int up = du[id] + 5;
while(pos < up)
{
tree[id][pos] += x;
pos += lowbit(pos);
}
}
int get_sum(int pos , int id)
{
int res = 0;
while(pos)
{
res += tree[id][pos];
pos -= lowbit(pos);
}
return res;
}
void init(int n)
{
TOT = 0;
rep(i , 1 , n) zero[i] = head[i] = du[i] = 0 , vec[i].clear();
}
void change(int u , int x)
{
if(!a[u]) for(auto i : vec[u]) zero[i] -- ;
else
{
for(auto i : vec[u])
{
if(a[u] > du[i]) continue ;
cnt[i][a[u]] -- ;
if(!cnt[i][a[u]]) add(a[u] , -1 , i);
}
}
if(!x)
{
for(auto i : vec[u]) zero[i] ++ ;
a[u] = x;
return ;
}
for(auto i : vec[u])
{
if(x > du[i]) continue ;
cnt[i][x] ++ ;
if(cnt[i][x] == 1) add(x , 1 , i);
}
a[u] = x;
}
int query1(int u)
{
rep(i , 0 , du[u]) vis[i] = 0;
for(int i = head[u] ; i ; i = edge[i].nex)
{
int v = edge[i].to ;
if(a[v] > du[u]) continue ;
vis[a[v]] ++ ;
}
rep(i , 0 , 330) if(!vis[i]) return i;
}
int query2(int u)
{
if(!zero[u]) return 0;
int l = 1 , r = du[u] , res = du[u];
while(l <= r)
{
int mid = l + r >> 1;
if(get_sum(mid , u) < mid) r = mid - 1 , res = mid;
else l = mid + 1;
}
return res;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0) , cout.tie(0);
int t ;
cin >> t;
while(t --)
{
cin >> n >> m ;
sq = sqrt(n);
rep(i , 1 , n) cin >> a[i];
rep(i , 1 , m)
{
int u , v;
cin >> u >> v;
du[u] ++ , du[v] ++ ;
}
rep(u , 1 , n)
{
for(int i = head[u] ; i ; i = edge[i].nex)
{
int v = edge[i].to;
if(du[v] >= sq) vec[u].push_back(v);
}
}
rep(u , 1 , n)
{
if(du[u] < sq) continue ;
tree[u].resize(du[u] + 10);
cnt[u].resize(du[u] + 10);
rep(j , 0 , du[u]) tree[u][j] = cnt[u][j] = 0;
for(int i = head[u] ; i ; i = edge[i].nex)
{
int v = edge[i].to ;
if(a[v] > du[u]) continue ;
if(!a[v]) {zero[u] ++ ; continue ;}
cnt[u][a[v]] ++ ;
if(cnt[u][a[v]] == 1) add(a[v] , 1 , u);
}
}
cin >> q;
while(q --)
{
int op , u , x;
cin >> op;
if(op == 1)
{
cin >> u >> x ;
change(u , x);
}
else
{
cin >> u;
if(du[u] <= sq) cout << query1(u) << '\n';
else cout << query2(u) << '\n';
}
}
init(n);
}
return 0;
}



# 1009

## 代码

#include<bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false),cin.tie(0);
#define ll long long
#define inf 0x3f3f3f3f
const int N=1e5+5;
//set<string>b;
//set<string>::iterator it;
struct node
{
ll p,a;
friend bool operator < (node a,node b)
{
return a.a==b.a?a.p>b.p:a.a>b.a;
}
}b[N],c[N],d[N];
double check(node a,node b)
{
return (a.p-b.p)*1.0/(b.a-a.a);
}
int main()
{
IO;
ll T,n,i,j,k,t,cnt;
cin>>T;
while(T--)
{
map<pair<int,int>,int>mp;
cin>>n;
for(i=1;i<=n;i++)
{
cin>>c[i].a>>c[i].p;
mp[make_pair(c[i].a,c[i].p)]++;
}
sort(c+1,c+1+n);
t=c[1].p;j=0;b[++j]=c[1];
for(i=2;i<=n;i++)
{
if(c[i].p>t)
{
t=c[i].p;b[++j]=c[i];
}
}
k=0;
for(i=j;i>=1;i--)
{
while(k>=2)
{
if(check(b[i],d[k])<=check(d[k],d[k-1]))
k--;
else
break;
}
d[++k]=b[i];
}
cnt=0;
for(i=1;i<=k;i++)
{
if(mp[make_pair(d[i].a,d[i].p)]==1)
cnt++;
}
cout<<cnt<<endl;
}
return 0;
}


• 点赞
• 评论
• 分享
x

海报分享

扫一扫，分享海报

• 收藏
• 手机看

分享到微信朋友圈

x

扫一扫，手机阅读

• 打赏

打赏

For the brave

你的鼓励将是我创作的最大动力

C币 余额
2C币 4C币 6C币 10C币 20C币 50C币
• 一键三连

点赞Mark关注该博主, 随时了解TA的最新博文