链接:
https://ac.nowcoder.com/acm/contest/42105
A
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
//constexpr int M = 998244353;
//constexpr int M = 1000000007;
template <typename T>
class Fenwick {
public:
int n;
vector<T> tree;
Fenwick(const int &n) : n(n), tree(n) {}
inline void modify(int pos, T x) {
for ( ; pos <= n; pos += pos & -pos) {
tree[pos - 1] += x;
}
}
inline T get(int pos) {
T res = 0;
for ( ; pos > 0; pos -= pos & -pos) {
res += tree[pos - 1];
}
return res;
}
inline T sum(int l, int r) { // (l, r]
return get(r) - get(l);
}
};
constexpr int N = 26;
int cnt[N];
int half[N];
void solve() {
int n;
string s;
cin >> n >> s;
s = " " + s;
Fenwick<int> f(n);
vector<vector<int>> pos(26);
for (int i = 1; i <= n; i++) {
int num = s[i] - 'a';
half[num]++;
}
for (int i = 0; i < 26; i++) {
half[i] /= 2;
}
vector<int> p(n + 1);
int tot = 0;
for (int i = 1; i <= n; i++) {
int num = s[i] - 'a';
if (cnt[num] < half[num]) {
p[i] = ++tot;
pos[num].push_back(tot);
} else {
p[i] = pos[num][cnt[num] - half[num]] + n / 2;
}
cnt[num]++;
}
i64 ans = 0;
for (int i = n; i >= 1; i--) {
ans += f.get(p[i]);
f.modify(p[i], 1);
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cout << fixed << setprecision(6);
int tt = 1;
//cin >> tt;
for (int _ = 1; _ <= tt; _++) {
solve();
}
return 0;
}
A和cf一个题差不多
链接:
https://codeforces.com/contest/1430/problem/E
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
//constexpr int M = 998244353;
//constexpr int M = 1000000007;
template <typename T>
class Fenwick {
public:
int n;
vector<T> tree;
Fenwick(const int &n) : n(n), tree(n) {}
inline void modify(int pos, T x) {
for ( ; pos <= n; pos += pos & -pos) {
tree[pos - 1] += x;
}
}
inline T get(int pos) {
T res = 0;
for ( ; pos > 0; pos -= pos & -pos) {
res += tree[pos - 1];
}
return res;
}
inline T sum(int l, int r) { // (l, r]
return get(r) - get(l);
}
};
constexpr int N = 26;
int cnt[N];
int half[N];
void solve() {
int n;
string s;
cin >> n >> s;
s = " " + s;
Fenwick<int> f(n);
vector<vector<int>> pos(26);
vector<int> p(n + 1);
for (int i = 1; i <= n; i++) {
int num = s[i] - 'a';
pos[num].push_back(i);
}
i64 ans = 0;
for (int i = 1; i <= n; i++) {
int num = s[i] - 'a';
p[n - i + 1] = pos[num].back();
pos[num].pop_back();
}
for (int i = n; i >= 1; i--) {
ans += f.get(p[i]);
f.modify(p[i], 1);
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cout << fixed << setprecision(6);
int tt = 1;
//cin >> tt;
for (int _ = 1; _ <= tt; _++) {
solve();
}
return 0;
}
F
找三个素数乘起来就行
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
//constexpr int M = 998244353;
//constexpr int M = 1000000007;
constexpr int N = 2E6;
vector<int> a;
bool st[N + 1];
void get() {
for (int i = 2; i <= N; i++) {
if (!st[i])
a.push_back(i);
for (int j = 0; 1LL * a[j] * i <= N; j++) {
st[i * a[j]] = 1;
if (i % a[j] == 0)
break;
}
}
}
void solve() {
int n;
cin >> n;
if (n == 1) {
cout << 24 << '\n';
return;
}
int A = *lower_bound(a.begin(), a.end(), 1 + n);
int B = *lower_bound(a.begin(), a.end(), A + n);
int C = *lower_bound(a.begin(), a.end(), B + n);
i64 ans = 1;
ans *= A;
ans *= B;
ans *= C;
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cout << fixed << setprecision(6);
int tt = 1;
cin >> tt;
get();
for (int _ = 1; _ <= tt; _++) {
solve();
}
return 0;
}
H
map套vector
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
//constexpr int M = 998244353;
//constexpr int M = 1000000007;
void solve() {
int n, m;
cin >> n >> m;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
map<vector<int>, int> mp;
i64 ans = 0;
for (int i = 0; i < m; i++) {
vector<int> b(n);
for (int j = 0; j < n; j++) {
cin >> b[j];
}
mp[b]++;
}
for (auto [u, v] : mp) {
ans += 1LL * v * (v - 1) / 2;
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cout << fixed << setprecision(6);
int tt = 1;
cin >> tt;
for (int _ = 1; _ <= tt; _++) {
solve();
}
return 0;
}
K
套个计算几何旋转向量公式
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
//constexpr int M = 998244353;
//constexpr int M = 1000000007;
const double Pi = acos(-1);
void solve() {
int t;
cin >> t;
double l1, l2, l3;
cin >> l1 >> l2 >> l3;
double t1, t2, t3;
cin >> t1 >> t2 >> t3;
cout << (-l1 * sin(-360.0 / t1 * t * Pi / 180.0)) +
(-l2 * sin(-360.0 / t2 * t * Pi / 180.0)) +
(-l3 * sin(-360.0 / t3 * t * Pi / 180.0)) << ' ' <<
(l1 * cos(-360.0 / t1 * t * Pi / 180.0)) +
(l2 * cos(-360.0 / t2 * t * Pi / 180.0)) +
(l3 * cos(-360.0 / t3 * t * Pi / 180.0));
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cout << fixed << setprecision(10);
int tt = 1;
//cin >> tt;
for (int _ = 1; _ <= tt; _++) {
solve();
}
return 0;
}
标签:std,四川省,int,pos,long,constexpr,2022,using
From: https://www.cnblogs.com/kiddingma/p/16767342.html