Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b7c120f

Browse files
committed
灵茶の试炼 * 41 (无UT)
1 parent bbb90b2 commit b7c120f

File tree

47 files changed

+5173
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+5173
-0
lines changed

‎algo-hub-cpp/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ add_executable(P3594 [POI2015] WIL "luogu/P3594 [POI2015] WIL.cpp")
1414
add_executable(P3901 数列找不同 "luogu/P3901 数列找不同.cpp")
1515
add_executable(P4513 小白逛公园 "luogu/P4513 小白逛公园.cpp")
1616
add_executable(P5490 【模板】扫描线 & 矩形面积并 "luogu/P5490 【模板】扫描线 & 矩形面积并.cpp")
17+
18+
add_executable(P3572 [POI 2014] PTA-Little Bird "luogu/P3572 [POI 2014] PTA-Little Bird.cpp")
19+
add_executable(P3694 邦邦的大合唱站队 "luogu/P3694 邦邦的大合唱站队.cpp")
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
typedef long long ll;
5+
6+
struct pair1 {
7+
int f, i;
8+
};
9+
10+
void solve() {
11+
int n;
12+
cin >> n;
13+
vector<int> a(n);
14+
for (int i = 0; i < n; ++i) {
15+
cin >> a[i];
16+
}
17+
18+
int t;
19+
cin >> t;
20+
while (t-- > 0) {
21+
int k;
22+
cin >> k;
23+
deque<pair1> dq; // f, i
24+
dq.push_back({0, 0});
25+
for (int i = 1; i < n; i++) {
26+
if (dq.front().i < i - k) {
27+
dq.pop_front();
28+
}
29+
int f = dq.front().f;
30+
if (a[i] >= a[dq.front().i]) {
31+
f++;
32+
}
33+
while (!dq.empty() && f < dq.back().f || f == dq.back().f && a[i] >= a[dq.back().i]) {
34+
dq.pop_back();
35+
}
36+
dq.push_back({f, i});
37+
}
38+
cout << dq.back().f << endl;
39+
}
40+
}
41+
42+
signed main() {
43+
ios::sync_with_stdio(false);
44+
cin.tie(nullptr);
45+
46+
int t = 1;
47+
// cin >> t;
48+
while (t--) solve();
49+
return 0;
50+
}
51+
52+
/*
53+
54+
*/
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
typedef long long ll;
5+
6+
void solve() {
7+
int n, m;
8+
cin >> n >> m;
9+
vector<int> a(n);
10+
for (int i = 0; i < n; ++i) {
11+
cin >> a[i];
12+
}
13+
14+
vector<vector<int> > sum(n + 1, vector<int>(20));
15+
for (int i = 1; i <= n; i++) {
16+
int v = a[i - 1];
17+
sum[i] = sum[i - 1];
18+
sum[i][v - 1]++;
19+
}
20+
21+
int u = 1 << m;
22+
vector<int> sz(u);
23+
for (int i = 0; i < m; i++) {
24+
int v = sum[n][i];
25+
int highBit = 1 << i;
26+
for (int mask = 0; mask < highBit; mask++) {
27+
int s = sz[mask];
28+
sz[highBit | mask] = s + v;
29+
}
30+
}
31+
32+
vector<int> f(u);
33+
for (int s = 0; s < u; s++) {
34+
int fs = f[s];
35+
// for cus, lb := u-1^s, 0; cus > 0; cus ^= lb {
36+
for (int cus = u - 1 ^ s, lb = 0; cus > 0; cus ^= lb) {
37+
lb = cus & -cus;
38+
int ns = s | lb;
39+
int p = __builtin_ctz(lb);
40+
f[ns] = max(f[ns], fs + sum[sz[ns]][p] - sum[sz[s]][p]);
41+
}
42+
}
43+
44+
int ans = n - f[u - 1];
45+
cout << ans << endl;
46+
}
47+
48+
signed main() {
49+
ios::sync_with_stdio(false);
50+
cin.tie(nullptr);
51+
52+
int t = 1;
53+
// cin >> t;
54+
while (t--) solve();
55+
return 0;
56+
}
57+
58+
/*
59+
60+
*/
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package c367;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
import java.util.Scanner;
6+
7+
public class Abc367_d {
8+
static int n, m;
9+
static int[] a;
10+
11+
public static void main(String[] args) {
12+
Scanner scanner = new Scanner(System.in);
13+
n = scanner.nextInt();
14+
m = scanner.nextInt();
15+
a = new int[n];
16+
for (int i = 0; i < n; i++) {
17+
a[i] = scanner.nextInt();
18+
}
19+
System.out.println(solve());
20+
}
21+
22+
private static String solve() {
23+
long sl = 0, sr = 0, ans = 0;
24+
Map<Long, Integer> cnt = new HashMap<>();
25+
for (int i = 0; i < n * 2 - 1; i++) {
26+
sr += a[i % n];
27+
if (i >= n - 1) {
28+
ans += cnt.getOrDefault(sr % m, 0);
29+
sl += a[i - n + 1];
30+
cnt.merge(sl % m, -1, Integer::sum);
31+
}
32+
cnt.merge(sr % m, 1, Integer::sum);
33+
}
34+
return String.valueOf(ans);
35+
}
36+
}
37+
/*
38+
D - Pedometer
39+
https://atcoder.jp/contests/abc367/tasks/abc367_d
40+
41+
灵茶の试炼 2025年05月13日
42+
题目大意:
43+
输入 n(2≤n≤2e5) m(1≤m≤1e6) 和长为 n 的数组 a(1≤a[i]≤1e9)。下标从 1 开始。
44+
一个环上有 n 个位置,顺时针编号从 1 到 n。
45+
从 i 顺时针移动到 i+1,需要走 a[i] 步。
46+
特别地,从 n 顺时针移动到 1,需要走 a[n] 步。
47+
输出有多少对位置 (s,t),满足 s≠t,且从 s 顺时针移动到 t 的最小步数是 m 的倍数。
48+
49+
断环为链,把 a 变成一个长为 2n-1 的数组 b。
50+
问题变成求有 b 中有多少个长度 <= n-1 的非空子数组,其元素和是 m 的倍数。
51+
如果你对此没有任何思路,可以做做我的 数据结构题单 中的 §1.2 前缀和与哈希表
52+
计算 b 的前缀和数组。用哈希表统计前缀和的出现次数。
53+
(下标从 0 开始)枚举在 [n-1,2n-2] 中的 t,计算有多少个符合要求的 s。
54+
如何保证长度 <= n-1?可以在枚举 t 的过程中,从哈希表中删除(出现次数减一)距离 t 太远的 s 的前缀和。(类似定长滑窗)
55+
代码 https://atcoder.jp/contests/abc367/submissions/64678165
56+
======
57+
58+
Input 1
59+
4 3
60+
2 1 4 3
61+
Output 1
62+
4
63+
64+
Input 2
65+
2 1000000
66+
1 1
67+
Output 2
68+
0
69+
70+
Input 3
71+
9 5
72+
9 9 8 2 4 4 3 5 3
73+
Output 3
74+
11
75+
*/

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /