CodeForces985G Team Players
2 seconds
256 megabytes
standard input
standard output
There are nn players numbered from 00 to n−1n−1 with ranks. The ii-th player has rank ii.
Players can form teams: the team should consist of three players and no pair of players in the team should have a conflict. The rank of the team is calculated using the following algorithm: let ii, jj, kk be the ranks of players in the team and i<j<ki<j<k, then the rank of the team is equal to A⋅i+B⋅j+C⋅kA⋅i+B⋅j+C⋅k.
You are given information about the pairs of players who have a conflict. Calculate the total sum of ranks over all possible valid teams modulo 264264.
The first line contains two space-separated integers nn and mm (3≤n≤2⋅1053≤n≤2⋅105, 0≤m≤2⋅1050≤m≤2⋅105) — the number of players and the number of conflicting pairs.
The second line contains three space-separated integers AA, BB and CC (1≤A,B,C≤1061≤A,B,C≤106) — coefficients for team rank calculation.
Each of the next mm lines contains two space-separated integers uiui and vivi (0≤ui,vi<n,ui≠vi0≤ui,vi<n,ui≠vi) — pair of conflicting players.
It's guaranteed that each unordered pair of players appears in the input file no more than once.
Print single integer — the total sum of ranks over all possible teams modulo 264264.
4 0
2 3 4
64
4 1
2 3 4
1 0
38
6 4
1 5 3
0 3
3 5
5 4
4 3
164
In the first example all 44 teams are valid, i.e. triples: {0, 1, 2}, {0, 1, 3}, {0, 2, 3} {1, 2, 3}.
In the second example teams are following: {0, 2, 3}, {1, 2, 3}.
In the third example teams are following: {0, 1, 2}, {0, 1, 4}, {0, 1, 5}, {0, 2, 4}, {0, 2, 5}, {1, 2, 3}, {1, 2, 4}, {1, 2, 5}.
AC代码为:
#include<bits/stdc++.h>
#define rep(i,x,y) for(register int i = x ;i <= y; ++ i)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
template<typename T>inline void read(T&x)
{
char c;int sign = 1;x = 0;
do { c = getchar(); if(c == '-') sign = -1; }while(!isdigit(c));
do { x = x * 10 + c - '0'; c = getchar(); }while(isdigit(c));
x *= sign;
}
const int N = 2e5 + 20;
ull a,b,c,n,m;
ull u[N],v[N],ans;
ull s1[N],s2[N],s3[N];
vector<int> g[N],f[N];
int main()
{
read(n); read(m);
read(a); read(b); read(c);
rep(i,1,m)
{
read(u[i]); read(v[i]);
if(u[i] > v[i]) swap(u[i],v[i]);
g[u[i]].push_back(v[i]);
f[v[i]].push_back(u[i]);
}
rep(i,0,n-1)
{
ull x = n - i - 1;
ans += a * i * (x * (x - 1) / 2);
ans += b * i * i * x;
ans += c * i * ((ull)i * (i - 1) / 2);
}
rep(i,1,m)
{
s1[ 0 ] += 1;
s1[u[i]] -= 1;
s1[ u[i] ] += n - u[i] - 2;
s1[u[i]+1] -= n - u[i] - 2;
s2[u[i]+1] += 1;
s2[ v[i] ] -= 1;
s2[ u[i] ] += u[i];
s2[u[i]+1] -= u[i];
s2[ v[i] ] += n - v[i] - 1;
s2[v[i]+1] -= n - v[i] - 1;
s3[v[i]+1] += 1;
s3[ n ] -= 1;
s3[ v[i] ] += v[i] - 1;
s3[v[i]+1] -= v[i] - 1;
}
rep(i,1,n)
s1[i] += s1[i - 1],
s2[i] += s2[i - 1],
s3[i] += s3[i - 1];
rep(i,0,n - 1)
{
ans -= a * i * s1[i];
ans -= b * i * s2[i];
ans -= c * i * s3[i];
}
rep(i,0,n-1) sort(g[i].begin(),g[i].end());
rep(i,0,n-1) sort(f[i].begin(),f[i].end());
rep(i,0,n-1)
{
int sz = g[i].size();
rep(j,0,sz - 1)
{
int k = j + 1;
while(k < sz)
{
ans += a * i;
ans += b * g[i][j];
ans += c * g[i][k];
k ++ ;
}
int SZ = g[g[i][j]].size();
rep(q,0,SZ - 1)
{
ans += a * i;
ans += b * g[i][j];
ans += c * g[g[i][j]][q];
}
}
sz = f[i].size();
rep(j,0,sz - 1)
{
int k = j + 1;
while(k < sz)
{
ans += a * f[i][j];
ans += b * f[i][k];
ans += c * i;
++ k;
}
}
}
rep(i,0,n-1)
{
int sz = g[i].size();
rep(j,0,sz - 1)
{
int t = j + 1,k = 0;
int SZ = g[g[i][j]].size();
while(t < sz && k < SZ)
{
if(g[i][t] == g[g[i][j]][k])
{
ans -= a * i;
ans -= b * g[i][j];
ans -= c * g[i][t];
++ t; ++ k;
}
else if(g[i][t] < g[g[i][j]][k]) ++ t;
else ++ k;
}
}
}
cout << ans << endl;
return 0;
}
CodeForces985G Team Players的更多相关文章
- Codeforces 985G. Team Players
Description 有 \(n\) 个人 , \(m\) 对人有冲突 , 你要从这 \(n\) 个人中选出三个人成为一组 , 使得同一组的人不存在一对有冲突 题面 Solution 容斥 答案=总 ...
- BZOJ.5407.girls/CF985G. Team Players(三元环计数+容斥)
题面 传送门(bzoj) 传送门(CF) \(llx\)身边妹子成群,这天他需要从\(n\)个妹子中挑出\(3\)个出去浪,但是妹子之间会有冲突,表现为\(i,j\)之间连有一条边\((i,j)\), ...
- [CF985G]Team Players
题意:给出一个图,求$\sum\limits_{\substack{i\lt j\lt k\\\nexists(i,j),(j,k),(i,k)}}Ai+Bj+Ck$ 挺好的一道题==,就是稍微毒了点 ...
- Codeforces 985G - Team Players(三元环)
Codeforces 题目传送门 & 洛谷题目传送门 真·ycx 做啥题我就做啥题 考虑枚举 \(j\),我们预处理出 \(c1_i\) 表示与 \(i\) 相连的编号 \(<i\) 的 ...
- Ten Qualities of an Effective Team Player
If you were choosing team members for a business team in your organization, who would the best team ...
- Model--汇总
NSFileManager.NSURL.NSFileHandle.NSData.NSXMLParser.NSUserDefaults.NSKeyedArchiver.NSKeyedUnarchiver ...
- 《C#本质论》读书笔记(14)支持标准查询操作符的集合接口
14.2.集合初始化器 使用集合初始化器,程序员可以采用和数组相似的方式,在集合的实例化期间用一套初始的成员来构造这个集合. 如果没有集合初始化器,就只有在集合实例化后才能显示添加到集合中--例如 ...
- ng-repeat的group
http://blog.csdn.net/violet_day/article/details/17023219 一.obj包含 <!doctype html> <html ng- ...
- ios9基础知识(技能篇)
NSFileManager.NSURL.NSFileHandle.NSData.NSXMLParser.NSUserDefaults.NSKeyedArchiver.NSKeyedUnarchiver ...
随机推荐
- ASP.NET Core 1.0: Deploy to IIS
尽管ASP.NET最新的官方文档记录了如何Deploy to IIS,但是实际操作起来依旧磕磕绊绊.官方文档地址:https://docs.asp.net/en/latest/publishing/i ...
- 领扣(LeetCode)有效的括号 个人题解
给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效. 有效字符串需满足: 左括号必须用相同类型的右括号闭合. 左括号必须以正确的顺序闭合. 注意空字符串可被认 ...
- docker中部署项目时遇到的问题
容器和宿主机时间不同步问题? 将本地时间复制到docker容器内的etc文件夹下即可 docker cp /etc/localtime scrapy_8:/etc/ 启动crontab错误? 报错: ...
- vue项目页面切换到默认显示顶部
页面切换到默认显示顶部 方法一 使用前端路由,当切换到新路由时,想要页面滚到顶部,或者是保持原先的滚动位置,就像重新加载页面那样. vue-router 能做到,而且更好,它让你可以自定义路由切换时页 ...
- java多线程,多线程加锁以及Condition类的使用
看了网上非常多的运行代码,很多都是重复的再说一件事,可能对于java老鸟来说,理解java的多线程是非常容易的事情,但是对于我这样的菜鸟来说,这个实在有点难,可能是我太菜了,网上重复的陈述对于我理解这 ...
- Android的系统框架的深入认识
Android采用层次化系统架构,官方公布的标准架构如下图所示.Android由底层往上分为4个主要功能层,分别是linux内核层(Linux Kernel),系统运行时库层(Libraries和An ...
- Theano中的导数
计算梯度 现在让我们使用Theano来完成一个稍微复杂的任务:创建一个函数,该函数计算相对于其参数x的某个表达式y的导数.为此,我们将使用宏T.grad.例如,我们可以计算相对于的梯度 import ...
- mysql的事物,外键,与常用引擎
### part1 时间类型 date YYYY-MM-DD 年月日 (出现日期) time HH:MM:SS 时分秒 (竞赛时间) year YYYY 年份值 (红酒年份 82年矿泉水) datet ...
- 使用FastReport报表工具实现信封套打功能
在较早期的报表套打的时候,我倾向于使用LODOP的ActiveX进行报表的打印或者套打,BS效果还是很不错的.之前利用它在Winform程序里面实现信封套打功能,详细参考<基于信封套打以及批量打 ...
- C语言I博客作业11
这个作业属于那个课程 C语言程序设计II 这个作业要求在哪里 https://edu.cnblogs.com/campus/zswxy/CST2019-1/homework/10132 我在这个课程的 ...