codeforces contest 1119
CF 1119 A
#include<bits/stdc++.h>
typedef long long ll;
#define rg register
template <typename T> inline void read(T&x){char cu=getchar();x=0;bool fla=0;while(!isdigit(cu)){if(cu=='-')fla=1;cu=getchar();}while(isdigit(cu))x=x*10+cu-'0',cu=getchar();if(fla)x=-x;}
template <typename T> inline void printe(const T x){if(x>=10)printe(x/10);putchar(x%10+'0');}
template <typename T> inline void print(const T x){if(x<0)putchar('-'),printe(-x);else printe(x);}
template <typename T> inline T min(const T a,const T b){return a<b?a:b;}
template <typename T> inline T max(const T a,const T b){return a>b?a:b;}
int n,a[300001],ans;
int main()
{read(n);for(rg int i=1;i<=n;i++)read(a[i]);for(rg int i=1;i<=n;i++)if(a[i]!=a[1])ans=max(ans,i-1);for(rg int i=1;i<=n;i++)if(a[i]!=a[n])ans=max(ans,n-i);print(ans);return 0;
}
CF 1119 B
#include<bits/stdc++.h>
typedef long long ll;
#define rg register
template <typename T> inline void read(T&x){char cu=getchar();x=0;bool fla=0;while(!isdigit(cu)){if(cu=='-')fla=1;cu=getchar();}while(isdigit(cu))x=x*10+cu-'0',cu=getchar();if(fla)x=-x;}
template <typename T> inline void printe(const T x){if(x>=10)printe(x/10);putchar(x%10+'0');}
template <typename T> inline void print(const T x){if(x<0)putchar('-'),printe(-x);else printe(x);}
template <typename T> inline T min(const T a,const T b){return a<b?a:b;}
template <typename T> inline T max(const T a,const T b){return a>b?a:b;}
int n,H,a[300001],b[300001],l,r,ans;
bool check(const int mid)
{for(rg int i=1;i<=mid;i++)b[i]=a[i];std::sort(b+1,b+mid+1);int cost=0;for(rg int i=mid;i>=0;i-=2){cost+=b[i];if(cost>H)return 0;}return 1;
}
int main()
{read(n),read(H),l=1,r=n;for(rg int i=1;i<=n;i++)read(a[i]);while(l<=r){const int mid=(l+r)>>1;if(check(mid))ans=mid,l=mid+1;else r=mid-1;}print(ans);return 0;
}
CF 1119 C
#include<bits/stdc++.h>
typedef long long ll;
#define rg register
template <typename T> inline void read(T&x){char cu=getchar();x=0;bool fla=0;while(!isdigit(cu)){if(cu=='-')fla=1;cu=getchar();}while(isdigit(cu))x=x*10+cu-'0',cu=getchar();if(fla)x=-x;}
template <typename T> inline void printe(const T x){if(x>=10)printe(x/10);putchar(x%10+'0');}
template <typename T> inline void print(const T x){if(x<0)putchar('-'),printe(-x);else printe(x);}
template <typename T> inline T min(const T a,const T b){return a<b?a:b;}
template <typename T> inline T max(const T a,const T b){return a>b?a:b;}
int n,m,a[501][501],fla=1;
int main()
{read(n),read(m);for(rg int i=1;i<=n;i++)for(rg int j=1;j<=m;j++)read(a[i][j]);for(rg int i=1;i<=n;i++)for(rg int j=1;j<=m;j++){int x;read(x);a[i][j]^=x^a[i-1][j]^a[i][j-1]^a[i-1][j-1];}for(rg int i=1;i<=n;i++)if(a[i][m])fla=0;for(rg int i=1;i<=m;i++)if(a[n][i])fla=0;if(fla)puts("Yes");else puts("No");return 0;
}
CF 1119 D
#include<bits/stdc++.h>
typedef long long ll;
#define rg register
template <typename T> inline void read(T&x){char cu=getchar();x=0;bool fla=0;while(!isdigit(cu)){if(cu=='-')fla=1;cu=getchar();}while(isdigit(cu))x=x*10+cu-'0',cu=getchar();if(fla)x=-x;}
template <typename T> inline void printe(const T x){if(x>=10)printe(x/10);putchar(x%10+'0');}
template <typename T> inline void print(const T x){if(x<0)putchar('-'),printe(-x);else printe(x);}
template <typename T> inline T min(const T a,const T b){return a<b?a:b;}
template <typename T> inline T max(const T a,const T b){return a>b?a:b;}
int n,q;
ll s[100001],c[100002],ans[100001],las=-1,dq=0,before;
int main()
{read(n);for(rg int i=1;i<=n;i++)read(s[i]);std::sort(s+1,s+n+1);n=std::unique(s+1,s+n+1)-s-1;ans[1]=n;for(rg int i=2;i<=n;i++)c[i]=s[i]-s[i-1];std::sort(c+1,c+n+1);c[n+1]=2000000000000000000ll;for(rg int i=2;i<=n+1;i++)if(c[i]!=dq){ans[i-1]=ans[i-2]+(dq-las-1)*before+n-i+2;before=n-i+2; las=dq,dq=c[i];}else ans[i-1]=ans[i-2];read(q);for(rg int i=1;i<=q;i++){ll x,y;read(x),read(y),y-=x;x=std::upper_bound(c+1,c+n+1,y)-c-1;print(ans[x]+(y-c[x])*(n-x+1)),putchar(' ');}return 0;
}
CF 1119 E
#include<bits/stdc++.h>
typedef long long ll;
#define rg register
template <typename T> inline void read(T&x){char cu=getchar();x=0;bool fla=0;while(!isdigit(cu)){if(cu=='-')fla=1;cu=getchar();}while(isdigit(cu))x=x*10+cu-'0',cu=getchar();if(fla)x=-x;}
template <typename T> inline void printe(const T x){if(x>=10)printe(x/10);putchar(x%10+'0');}
template <typename T> inline void print(const T x){if(x<0)putchar('-'),printe(-x);else printe(x);}
template <typename T> inline T min(const T a,const T b){return a<b?a:b;}
template <typename T> inline T max(const T a,const T b){return a>b?a:b;}
ll n,a[300001],all,usd,ans;
int main()
{read(n);for(rg int i=0;i<n;i++)read(a[i]),all+=a[i];for(rg int i=n-1;i>=0;i--){int A=min(all-usd,a[i]),other=a[i]-A;if((all-usd-A)*2<=A){ll add=all-usd-A;usd+=add,A-=add*2,ans+=add;add=A/3;A-=add*3,ans+=add;usd=max(usd-A,0ll);}else{ll add=A/2;usd+=add,A-=add*2,ans+=add;usd=max(usd-A,0ll);}usd=max(usd-other,0ll),all-=a[i];}print(ans);return 0;
}
CF 1119 F
#include<bits/stdc++.h>
typedef long long ll;
#define rg register
template <typename T> inline void read(T&x){char cu=getchar();x=0;bool fla=0;while(!isdigit(cu)){if(cu=='-')fla=1;cu=getchar();}while(isdigit(cu))x=x*10+cu-'0',cu=getchar();if(fla)x=-x;}
template <typename T> inline void printe(const T x){if(x>=10)printe(x/10);putchar(x%10+'0');}
template <typename T> inline void print(const T x){if(x<0)putchar('-'),printe(-x);else printe(x);}
template <typename T> inline T min(const T a,const T b){return a<b?a:b;}
template <typename T> inline T max(const T a,const T b){return a>b?a:b;}
template <typename T> inline T gcd(const T a,const T b){if(!b)return a;return gcd(b,a%b);}
template <typename T> inline void maxd(T&a,const T b){a=a>b?a:b;}
template <typename T> inline T abs(const T a){return a>0?a:-a;}
const int maxn=250001,maxm=500001;
int n,head[maxn],nxt[maxm],tow[maxm],vau[maxm],tmp,d[maxn];
inline void addb(const int u,const int v,const int w)
{tmp++;nxt[tmp]=head[u];head[u]=tmp;tow[tmp]=v;vau[tmp]=w;
}
std::vector<int>T[maxn];
int fa[maxn],nex[maxn+1],las;
void ffa(const int u)
{for(rg int i=head[u];i;i=nxt[i]){const int v=tow[i];if(v!=fa[u])fa[v]=u,ffa(v);}
}
bool vis[maxn];
struct SET
{std::multiset<int,std::greater<int> >main;std::vector<int>erased,added;ll lj;int tot;void insert(const int x){main.insert(x),lj+=x,tot++;}void resize(const int x){while(tot>x){tot--,lj-=*main.begin();main.erase(main.begin());}}void RESIZE(const int x){while(tot>x){tot--,lj-=*main.begin(),erased.push_back(*main.begin());main.erase(main.begin());}}void INSERT(const int x){main.insert(x),lj+=x,tot++;added.push_back(x);}void BACK(){for(std::vector<int>::iterator Pos=erased.begin();Pos!=erased.end();Pos++)main.insert(*Pos),tot++,lj+=*Pos;erased.clear();for(std::vector<int>::iterator Pos=added.begin();Pos!=added.end();Pos++)main.erase(main.find(*Pos)),tot--,lj-=*Pos;added.clear();}
}s[maxn];
ll f[maxn][2];
int G;
void dfs(const int u)
{int ned=d[u]-G;s[u].resize(ned);ll tot=0;int *lc=&head[u];for(rg int i=head[u];i;i=nxt[i]){const int v=tow[i];if(vis[v]){(*lc)=nxt[i];continue;}else lc=&nxt[i];if(v!=fa[u]){dfs(v);if(f[v][1]+vau[i]<=f[v][0])ned--,tot+=f[v][1]+vau[i];else{tot+=f[v][0];s[u].INSERT(f[v][1]+vau[i]-f[v][0]);}}}s[u].RESIZE(max(ned,0));f[u][0]=s[u].lj+tot;ned--;s[u].RESIZE(max(ned,0));f[u][1]=s[u].lj+tot;s[u].BACK();
}
int main()
{read(n);for(rg int i=1;i<n;i++){int u,v,w;read(u),read(v),read(w);addb(u,v,w),addb(v,u,w),d[u]++,d[v]++;}for(rg int i=1;i<=n;i++)T[d[i]].push_back(i);for(rg int i=n;i>=1;i--){nex[i]=las;if(!T[i].empty())las=i;}vis[0]=1;ffa(1);for(rg int i=1;i<=n;i++){G=i-1;ll ans=0;for(rg int p=i;p;p=nex[p]){for(std::vector<int>::iterator Pos=T[p].begin();Pos!=T[p].end();Pos++)if(vis[fa[*Pos]]){dfs(*Pos);ans+=f[*Pos][0];}}print(ans),putchar('\n');for(std::vector<int>::iterator Pos=T[i].begin();Pos!=T[i].end();Pos++){const int u=*Pos;vis[u]=1;for(rg int j=head[u];j;j=nxt[j]){const int v=tow[j];if(!vis[v])s[v].insert(vau[j]);}}}return 0;
}
CF 1119 G
#include<bits/stdc++.h>
typedef long long ll;
#define rg register
template <typename T> inline void read(T&x){char cu=getchar();x=0;bool fla=0;while(!isdigit(cu)){if(cu=='-')fla=1;cu=getchar();}while(isdigit(cu))x=x*10+cu-'0',cu=getchar();if(fla)x=-x;}
template <typename T> inline void printe(const T x){if(x>=10)printe(x/10);putchar(x%10+'0');}
template <typename T> inline void print(const T x){if(x<0)putchar('-'),printe(-x);else printe(x);}
template <typename T> inline T min(const T a,const T b){return a<b?a:b;}
template <typename T> inline T max(const T a,const T b){return a>b?a:b;}
template <typename T> inline T gcd(const T a,const T b){if(!b)return a;return gcd(b,a%b);}
template <typename T> inline void maxd(T&a,const T b){a=a>b?a:b;}
template <typename T> inline T abs(const T a){return a>0?a:-a;}
int n,m,a[1000001],b[1000001],k[1000001],all,pl[1000001];
int main()
{read(n),read(m);for(rg int i=1;i<=m;i++)read(a[i]),b[i]=a[i],all+=a[i];for(rg int i=1;i<=m;i++){k[i]=a[i]%n;if(k[i]){int las=n-k[i];for(int j=i+1;j<=m+1;j++)if(a[j]<las&&j!=m+1){k[j]=k[j-1]+a[j];las-=a[j];}else{i=j-1;a[j]-=las;break;}}}std::sort(k+1,k+m);print((all+n-1)/n),putchar('\n');k[m]=n;for(rg int i=1;i<=m;i++)print(k[i]-k[i-1]),putchar(' '),pl[k[i]]=i;putchar('\n');for(rg int i=1;i<=m;i++)a[i]=b[i];for(rg int i=1;i<=m;i++){while(a[i]>=n){a[i]-=n;for(rg int j=1;j<=m;j++)print(i),putchar(' ');putchar('\n');}k[i]=a[i];if(k[i]>0&&i==m){for(rg int j=1;j<=m;j++)print(i),putchar(' ');putchar('\n');}else if(k[i]>0){int las=n-k[i],zq=0;while(zq<pl[k[i]])zq++,print(i),putchar(' ');for(int j=i+1;j<=m;j++)if(j==m){i=j-1;a[j]-=las;while(zq<m)zq++,print(j),putchar(' ');break;}else if(a[j]<las){k[j]=k[j-1]+a[j];las-=a[j];while(zq<pl[k[j]])zq++,print(j),putchar(' ');}else{i=j-1;a[j]-=las;while(zq<m)zq++,print(j),putchar(' ');break;}putchar('\n');}}return 0;
}
CF 1119 H
#include<bits/stdc++.h>
typedef long long ll;
#define rg register
template <typename T> inline void read(T&x){char cu=getchar();x=0;bool fla=0;while(!isdigit(cu)){if(cu=='-')fla=1;cu=getchar();}while(isdigit(cu))x=x*10+cu-'0',cu=getchar();if(fla)x=-x;}
template <typename T> inline void printe(const T x){if(x>=10)printe(x/10);putchar(x%10+'0');}
template <typename T> inline void print(const T x){if(x<0)putchar('-'),printe(-x);else printe(x);}
template <typename T> inline T min(const T a,const T b){return a<b?a:b;}
template <typename T> inline T max(const T a,const T b){return a>b?a:b;}
const int mod=998244353,inv2=(mod+1)>>1,maxn=131072;
int Md(const int x){return x>=mod?x-mod:x;}
ll pow(ll x,ll y)
{ll res=1;x=(x+mod+mod)%mod;for(;y;y>>=1,x=x*x%mod)if(y&1)res=res*x%mod;return res;
}
int n,k,lenth;
inline void FWT(ll*A)
{for(rg int i=1;i<lenth;i<<=1)for(rg int j=0;j<lenth;j+=(i<<1))for(rg int k=0;k<i;k++){const int x=A[j+k],y=A[j+k+i];A[j+k]=(x+y),A[j+k+i]=(x-y);}
}
inline void FWT(ll*A,const int fla)
{for(rg int i=1;i<lenth;i<<=1)for(rg int j=0;j<lenth;j+=(i<<1))for(rg int k=0;k<i;k++){const int x=A[j+k],y=A[j+k+i];A[j+k]=Md(x+y),A[j+k+i]=Md(x+mod-y);}if(fla==-1){const int inv=pow(inv2,(ll)k);for(rg int i=0;i<lenth;i++)A[i]=(ll)A[i]*inv%mod;}
}
ll A[maxn],B[maxn],C[maxn],x,y,z,v;
int main()
{read(n),read(k),read(x),read(y),read(z),lenth=1<<k;for(rg int i=1;i<=n;i++){int a,b,c;read(a),read(b),read(c);v^=a,b^=a,c^=a,a=b^c;A[b]++,B[c]++,C[a]++;}FWT(A),FWT(B),FWT(C);for(rg int p=0;p<lenth;p++){const ll a=n,b=A[p],c=B[p],d=C[p];A[p]=pow(x+y+z,(a+b+c+d)/4)*pow(x+y-z,(a+b-c-d)/4)%mod*pow(x-y+z,(a-b+c-d)/4)%mod*pow(x-y-z,(a-b-c+d)/4)%mod;}FWT(A,-1);for(rg int i=0;i<lenth;i++)print(A[i^v]),putchar(' ');return 0;
}
codeforces contest 1119相关推荐
- codeforces contest 1166 E. The LCMs Must be Large---思维
题目链接:https://codeforces.com/contest/1166/problem/E 题解: 代码: #include<bits/stdc++.h> using names ...
- codeforces contest 1142
前言 这个contest是div1的,div2的题其实也做了一下,但这里就不贴出了 CF 1142 A 题目大意:有nnn个城市排成一圈,相邻两个城市距离为kkk,一个人从起点SSS(SSS未给出)开 ...
- codeforces contest 1140(D~G)
前言 A~C不想写博客了,就不写了,后面的题还是要推一推的,所以写一下 CF 1140 D 题目大意: 给出一个正多边形,顶点按顺序标号为111~nnn,一个三角划分的权值是每个三角形三个顶点的编号乘 ...
- CodeForces Contest #1114: Round #538 (Div. 2)
比赛传送门:CF #1114. 比赛记录:点我. 又 FST 了. [A]Got Any Grapes? 题意简述: 有三个人,第一个人需要吃绿色葡萄至少 \(a\) 个,第二个人需要吃绿色和紫色葡萄 ...
- Codeforces Contest 1138 problem B Circus —— 死亡1700,暴力
Polycarp is a head of a circus troupe. There are n - an even number - artists in the troupe. It is k ...
- codeforces contest 869 problem C(组合数)
The Intriguing Obsession time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Codeforces Contest 1144 E Median String —— 水题
This way 题意: 给你两个字符串,问你字典序在这两个字符串正中间的字符串是什么 题解: 好几个星期没做题目了,连1900都想了一段时间,一开始想着用2进制来做,但是想着想着发现直接用2进制做不 ...
- Codeforces Contest 1110 problem E Magic Stones —— 更改算式
Grigory has n magic stones, conveniently numbered from 1 to n. The charge of the i-th stone is equal ...
- codeforces contest 985E. Pencils and Boxes+思维
类似指针的想法 E. Pencils and Boxes time limit per test 2 seconds memory limit per test 256 megabytes input ...
最新文章
- 纸牌游戏CardBattle的设计与开发
- mysql group by与order by的研究--分类中最新的内容
- SpringMVC中@ResponseBody的相关注意点
- 编写一个猜数字游戏程序:
- Flex mp3播放
- php中的css类怎么查找,CSS 样式表中的类和伪类
- 2022.管理类软件工具
- oracle 索引 lob 迁移,Oracle 11g到19c迁移TB级lob表的酸爽
- Mybatis存储过程调用
- 普通人快速拿到校招offer的十大狠招
- Membership Leakage in Label-Only Exposures论文解读
- thinkphp 3.+ Apache url重写问题(.htaccess)
- ESP车身电子稳定系统
- 超级强大灵活的文件批量修改文件名工具,彻底告别手工改名的烦恼
- SPA是什么及原生js实现简易SPA单页面
- 计算机视觉笔记及资料整理(含图像分割、目标检测)
- swr,解决 React 项目 API 调用的最好方案
- 会做饭,擅长烹饪,会给你的工作生活带来怎样的不同?
- 针对L型区域的椭圆方程的差分法
- 中国大学MOOC大学生心理健康试题及答案