大吉大利
链接:https://ac.nowcoder.com/acm/contest/12221/A
来源:牛客网
题目描述
给定nn个整数,依次为a_1,a_2,…,a_na
1
,a
2
,…,a
n
。
求\sum_{i = 1}^n\sum_{j = 1}^n(a_i&a_j)∑
i=1
n
∑
j=1
n
(a
i
&a
j
)。“&&”是二进制的与运算符。
输入描述:
第一行一个整数nn.
第二行nn个整数a_ia
i
.
输出描述:
一个整数表示上述求和式的答案.
示例1
输入
复制
5
1 2 3 4 5
输出
复制
33
备注:
1 \leq n \leq 1e51≤n≤1e5
0 \leq a_i \leq 1e80≤a
i
≤1e8
涉及二进制的,枚举每一位是非常有效的
/* _
_ooOoo_
o8888888o
88" . "88
(| -_- |)
.' \\| |// `.
/ \\||| : |||// \
/ _||||| -:- |||||_ \
| | \\\ - /'| | |
| \_| `\`---'// |_/ |
\ .-\__ `-. -'__/-. /
___`. .' /--.--\ `. .'___
."" '< `.___\_<|>_/___.' _> \"".
| | : `- \`. ;`. _/; .'/ / .' ; |
\ \ `-. \_\_`. _.'_/_/ -' _.' /
===========`-.`___`-.__\ \___ /__.-'_.'_.-'================
Please give me AC.
*/
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <map>
#include <unordered_map>
#include <vector>
#include <cmath>
//#include <ext/rope>
#include <bits/stdc++.h>
using namespace std;
//using namespace __gnu_cxx;
#define gt(x) x = read()
#define int long long
#define ios ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl "\n"
//#define x first
//#define y second
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
typedef __int128 INT;
typedef pair<double, int> PDI;
typedef pair<int, int> PII;
typedef unsigned long long ULL;
inline int read(){
int x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9'){
if (ch == '-')
f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9'){
x = (x<<1) + (x<<3) + (ch^48);
ch = getchar();
}
return x * f;
}
inline void print(int x) {
if (x < 0) { putchar('-'); x = -x; }
if (x >= 10) print(x / 10);
putchar(x % 10 + '0');
}
const int N = 1e5 + 10;
const int M = 3 * N;
const int mod = 998244353;
const int PP = 131;
const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-10;
const double PI = acos(-1);
int sum[50];
int n;
int a[N];
signed main(){
ios;
cin >> n;
for (int i = 1; i <= n; i ++) cin >> a[i];
for (int i = 1; i <= n; i ++){
for (int j = 0; j <= 40; j ++){
if ((a[i] >> j) & 1){
sum[j] ++;
}
}
}
INT ans = 0;
for (int i = 0; i <= 40; i ++){
/// cout << i << "-----" << sum[i] << endl;
ans += ((sum[i] * sum[i]) * (1ll << i));
}
print(ans);
// cout << endl;
return 0;
}
三角形周长和
链接:https://ac.nowcoder.com/acm/contest/12221/B
来源:牛客网
题目描述
给定平面上nn个点的坐标,并且我们定义两个点的距离为曼哈顿距离.
曼哈顿距离是指对两个点(x_1,y_1),(x_2,y_2)(x
1
,y
1
),(x
2
,y
2
),他们之间的距离为|x_2 - x_1| + |y_2 - y_1|∣x
2
−x
1
∣+∣y
2
−y
1
∣.
.众所周知三个点可以构成一个三角形,那么nn个点可以构成C_n^3C
n
3
个三角形,现在你需要求出所有三角形的周长和 输出在模998244353998244353意义下的答案.数据保证不存在三点共线.
输入描述:
第一行一个整数表示nn.
接下来nn行每行两个整数x,yx,y表示一个点.
输出描述:
输出一个整数表示周长和.
示例1
输入
复制
3
0 0
1 0
1 1
输出
复制
4
备注:
3 \leq n \leq 1e33≤n≤1e3
-1e9 \leq x, y \leq 1e9−1e9≤x,y≤1e9
枚举任意两个点,都有可能和剩下的所有点构成三角形,所以每个曼哈顿距离的贡献是n-2
/* _
_ooOoo_
o8888888o
88" . "88
(| -_- |)
.' \\| |// `.
/ \\||| : |||// \
/ _||||| -:- |||||_ \
| | \\\ - /'| | |
| \_| `\`---'// |_/ |
\ .-\__ `-. -'__/-. /
___`. .' /--.--\ `. .'___
."" '< `.___\_<|>_/___.' _> \"".
| | : `- \`. ;`. _/; .'/ / .' ; |
\ \ `-. \_\_`. _.'_/_/ -' _.' /
===========`-.`___`-.__\ \___ /__.-'_.'_.-'================
Please give me AC.
*/
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <map>
#include <unordered_map>
#include <vector>
#include <cmath>
//#include <ext/rope>
#include <bits/stdc++.h>
using namespace std;
//using namespace __gnu_cxx;
#define gt(x) x = read()
#define int long long
#define ios ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl "\n"
//#define x first
//#define y second
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
//typedef __int128 INT;
typedef pair<double, int> PDI;
typedef pair<int, int> PII;
typedef unsigned long long ULL;
inline int read(){
int x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9'){
if (ch == '-')
f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9'){
x = (x<<1) + (x<<3) + (ch^48);
ch = getchar();
}
return x * f;
}
inline void print(int x) {
if (x < 0) { putchar('-'); x = -x; }
if (x >= 10) print(x / 10);
putchar(x % 10 + '0');
}
const int N = 1e3 + 10;
const int M = 3 * N;
const int mod = 998244353;
const int PP = 131;
const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-10;
const double PI = acos(-1);
int x[N], y[N];
int n;
int get_dist(int i, int j){
return abs(x[i] - x[j]) + abs(y[i] - y[j]);
}
signed main(){
ios;
cin >> n;
for (int i = 1; i <= n; i ++){
cin >> x[i] >> y[i];
}
int ans = 0;
for (int i = 1; i <= n; i ++){
for (int j = i + 1; j <= n; j ++){
ans += (n - 2) * (get_dist(i, j)) % mod;
ans %= mod;
}
}
cout << ans << endl;
return 0;
}