# 正睿线上集训1

### B

#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<vector>
#include<ctime>
#include<cmath>
#include<set>
#include<map>
#define LL long long
#define pii pair<int,int>
#define mk make_pair
#define fi first
#define se second
using namespace std;
const int N = 2e5 + 3;
const int block = 499;
int e[505][505];
vector <int> G[N];
vector <int> BIG;
int n,m,k;
int co[N],num[N],idx[N];
bool book[N];
int tag[N];
{
int v = 0,c = 1;char ch = getchar();
while(!isdigit(ch))
{
if(ch == '-') c = -1;
ch = getchar();
}
while(isdigit(ch))
{
v = v * 10 + ch - 48;
ch = getchar();
}
return v * c;
}
int main(){
for(int i = 1;i <= n;++i)
{
if(co[i] == co[i - 1])
{
i--;
n--;
continue;
}
num[co[i]]++;
}
co[0] = 0,co[n + 1] = 0;
for(int i = 0;i <= n;++i)
{
G[co[i]].push_back(co[i + 1]);
G[co[i + 1]].push_back(co[i]);
}
for(int i = 1;i <= k;++i)
{
if(G[i].size() > block)
{
BIG.push_back(i);
idx[i] = BIG.size();
}
}
for(int u = 0;u < (int)BIG.size();++u)
{
for(int v = 0;v < (int)G[BIG[u]].size();++v)
{
int x = BIG[u],y = G[x][v];
if(G[y].size() > block) e[idx[x]][idx[y]]++;
}
}
int V = 0,E = 0;
while(m--){
int w = book[x] ? -1 : 1;
V += w * num[x];
if(G[x].size() < block){
for(int i = 0;i < (int)G[x].size();++i){
if(G[G[x][i]].size() < block){
if(book[x] == 1 && book[G[x][i]] == 1) E--;
if(book[x] == 0 && book[G[x][i]] == 1) E++;
}
else{
if(book[x] == 1 && book[G[x][i]] == 1) E--;
if(book[x] == 0 && book[G[x][i]] == 1) E++;
if(book[x] == 0) tag[G[x][i]]++;
else tag[G[x][i]]--;
}
}
}
else{
for(int i = 0;i < (int)BIG.size();++i){
if(x == BIG[i]) continue;
if(book[x] == 1 && book[BIG[i]] == 1) E -= e[idx[x]][idx[BIG[i]]];
if(book[x] == 0 && book[BIG[i]] == 1) E += e[idx[x]][idx[BIG[i]]];
}
E += w * tag[x];
}
printf("%d\n",V - E);
book[x] ^= 1;
}
return 0;
}



### C

$f_{i + 1,j} = f_{i,j}\times p^{j} + f_{i,j - 1} \times q^{i - j + 1}$

$f_{i + 1,j} = f_{i,j} \times q^j + f_{i,j - 1} \times p^{i - j + 1}$

$f_{i,j} \times p^j + f_{i,j - 1}\times q^{i- j + 1} =f_{i,j} \times q^{j} +f_{i,j - 1}\times p^{i - j + 1}$

$f_{i,j} = f_{i,j - 1}\times \frac{(p^{i - j + 1}-q^{i - j + 1})}{p^j - q^j}$

$p = q$是应该怎么做,这时候发现胜负和编号没有关系了,也就是我们直接组合数学

$ans_k = \binom{n}{k}\frac{1}{2^{k\times (n - k)}}$

#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<vector>
#include<ctime>
#include<cmath>
#include<set>
#include<map>
#define LL long long
#define pii pair<int,int>
#define mk make_pair
#define fi first
#define se second
using namespace std;
const int N = 2e5 + 3;
const int block = 499;
int e[505][505];
vector <int> G[N];
vector <int> BIG;
int n,m,k;
int co[N],num[N],idx[N];
bool book[N];
int tag[N];
{
int v = 0,c = 1;char ch = getchar();
while(!isdigit(ch))
{
if(ch == '-') c = -1;
ch = getchar();
}
while(isdigit(ch))
{
v = v * 10 + ch - 48;
ch = getchar();
}
return v * c;
}
int main(){
for(int i = 1;i <= n;++i)
{
if(co[i] == co[i - 1])
{
i--;
n--;
continue;
}
num[co[i]]++;
}
co[0] = 0,co[n + 1] = 0;
for(int i = 0;i <= n;++i)
{
G[co[i]].push_back(co[i + 1]);
G[co[i + 1]].push_back(co[i]);
}
for(int i = 1;i <= k;++i)
{
if(G[i].size() > block)
{
BIG.push_back(i);
idx[i] = BIG.size();
}
}
for(int u = 0;u < (int)BIG.size();++u)
{
for(int v = 0;v < (int)G[BIG[u]].size();++v)
{
int x = BIG[u],y = G[x][v];
if(G[y].size() > block) e[idx[x]][idx[y]]++;
}
}
int V = 0,E = 0;
while(m--){
int w = book[x] ? -1 : 1;
V += w * num[x];
if(G[x].size() < block){
for(int i = 0;i < (int)G[x].size();++i){
if(G[G[x][i]].size() < block){
if(book[x] == 1 && book[G[x][i]] == 1) E--;
if(book[x] == 0 && book[G[x][i]] == 1) E++;
}
else{
if(book[x] == 1 && book[G[x][i]] == 1) E--;
if(book[x] == 0 && book[G[x][i]] == 1) E++;
if(book[x] == 0) tag[G[x][i]]++;
else tag[G[x][i]]--;
}
}
}
else{
for(int i = 0;i < (int)BIG.size();++i){
if(x == BIG[i]) continue;
if(book[x] == 1 && book[BIG[i]] == 1) E -= e[idx[x]][idx[BIG[i]]];
if(book[x] == 0 && book[BIG[i]] == 1) E += e[idx[x]][idx[BIG[i]]];
}
E += w * tag[x];
}
printf("%d\n",V - E);
book[x] ^= 1;
}
return 0;
}


posted @ 2019-10-14 22:00  wyxdrqcccc  阅读(57)  评论(0编辑  收藏