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 ...
随机推荐
- C# web项目中sql数据库转sqlite数据库
最近做了一个小网站,用到了一个使用sql server 2005的.net cms系统,但是现在我所买虚拟主机的服务商,不给虚拟主机提供sql server服务了,那就转数据库吧,转啥好呢,思来想去, ...
- 推荐Java五大微服务器及其代码示例教程
来源素文宅博客:http://blog.yoodb.com/yoodb/article/detail/1339 微服务越来越多地用于开发领域,因为开发人员致力于创建更大,更复杂的应用程序,这些应用程序 ...
- nyoj 35-表达式求值(stack, 栈的应用)
35-表达式求值 内存限制:64MB 时间限制:3000ms Special Judge: No accepted:37 submit:53 题目描述: ACM队的mdd想做一个计算器,但是,他要做的 ...
- nyoj 75-日期计算 (闰年与平年的判断)
75-日期计算 内存限制:64MB 时间限制:3000ms 特判: No 通过数:19 提交数:31 难度:1 题目描述: 如题,输入一个日期,格式如:2010 10 24 ,判断这一天是这一年中的第 ...
- nyoj 92-图像有用区域 (BFS)
92-图像有用区域 内存限制:64MB 时间限制:3000ms 特判: No 通过数:4 提交数:12 难度:4 题目描述: “ACKing”同学以前做一个图像处理的项目时,遇到了一个问题,他需要摘取 ...
- 领扣(LeetCode)二维区域和检索 个人题解
给定一个二维矩阵,计算其子矩形范围内元素的总和,该子矩阵的左上角为 (row1, col1) ,右下角为 (row2, col2). 上图子矩阵左上角 (row1, col1) = (2, 1) ,右 ...
- byteCTF 2019
本文作者:z3r0yu 由“合天智汇”公众号首发,未经允许,禁止转载! 0x00 前言 周末的比赛质量还是挺高的,特别是boring_code,有点烧脑但是做的就很开心. 0x01 boring_c ...
- java.lang.NoSuchMethodError: org.apache.tomcat.JarScanner.scan(Ljavax/servlet/ServletContext;Ljava/lang/ClassLoader;Lorg/apache/tomcat/JarScannerCallback;Ljava/util/Set;)V
java.lang.NoSuchMethodError: org.apache.tomcat.JarScanner.scan(Ljavax/servlet/ServletContext;Ljava/l ...
- Python 深入浅出支持向量机(SVM)算法
相比于逻辑回归,在很多情况下,SVM算法能够对数据计算从而产生更好的精度.而传统的SVM只能适用于二分类操作,不过却可以通过核技巧(核函数),使得SVM可以应用于多分类的任务中. 本篇文章只是介绍SV ...
- Component 和 PureComponent 的区别;复制demo,肉眼可以的区别
React.PureComponent它用当前与之前 props 和 state 的浅比较覆写了 shouldComponentUpdate() 的实现.简单来说,就是PureComponent简单实 ...