Skip to content

Commit 8da171c

Browse files
author
ksh-code
committed
y
1 parent 9bef859 commit 8da171c

File tree

20 files changed

+636
-53
lines changed

20 files changed

+636
-53
lines changed

1.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.

1168.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef long long ll;
4+
5+
const int MAX = 1e5;
6+
7+
int tree[MAX*4];
8+
9+
int query(int s, int e, int node, int rank) {
10+
if (s == e) return s;
11+
12+
int m = (s+e)/2;
13+
if (tree[node*2] >= rank) return query(s, m, node*2, rank);
14+
else return query(m+1, e, node*2+1, rank-tree[node*2]);
15+
}
16+
17+
void update(int s, int e, int node, int index, int diff) {
18+
if (e < index || index < s) return;
19+
tree[node] += diff;
20+
if (s == e) return;
21+
22+
int m = (s+e)/2;
23+
update(s, m, node*2, index, diff);
24+
update(m+1, e, node*2+1, index, diff);
25+
}
26+
27+
void solve(){
28+
int N,K; cin >> N >> K;
29+
for (int i = 1; i <= N; i++) update(1, N, 1, i, 1);
30+
31+
int step = 1;
32+
for (int i = 1; i <= N; i++) {
33+
step = (step + (K-1)) % (N-i+1);
34+
if (step == 0) step = N-i+1;
35+
36+
int result = query(1, N, 1, step);
37+
cout << result;
38+
update(1, N, 1, result, -1);
39+
if (i < N) cout << ", ";
40+
}
41+
}
42+
43+
int main()
44+
{
45+
cin.tie(0)->sync_with_stdio(false);
46+
cout << '<';
47+
solve();
48+
cout << '>';
49+
return 0;
50+
}

1289.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef long long ll;
4+
5+
const int MAX = 1e6;
6+
7+
int tree[MAX*4];
8+
9+
int query(int s, int e, int node, int rank) {
10+
if (s == e) return s;
11+
12+
int m = (s+e)/2;
13+
if (tree[node*2] >= rank) return query(s, m, node*2, rank);
14+
else return query(m+1, e, node*2+1, rank-tree[node*2]);
15+
}
16+
17+
void update(int s, int e, int node, int index, int diff) {
18+
if (e < index || index < s) return;
19+
tree[node] += diff;
20+
if (s == e) return;
21+
22+
int m = (s+e)/2;
23+
update(s, m, node*2, index, diff);
24+
update(m+1, e, node*2+1, index, diff);
25+
}
26+
27+
void solve(){
28+
int N; cin >> N;
29+
30+
for (int i = 0; i < N; i++) {
31+
int a; cin >> a;
32+
if (a != 1) {
33+
int b,c; cin >> b>>c;
34+
update(1,MAX,1,b,c);
35+
} else {
36+
int b; cin >> b;
37+
int result = query(1, MAX, 1, b);
38+
cout << result << '\n';
39+
update(1,MAX,1,result,-1);
40+
}
41+
}
42+
}
43+
44+
int main()
45+
{
46+
cin.tie(0)->sync_with_stdio(false);
47+
solve();
48+
return 0;
49+
}

12899.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef long long ll;
4+
5+
const int MAX = 2e6;
6+
7+
int tree[MAX*4];
8+
9+
int query(int s, int e, int node, int rank) {
10+
if (s == e) return s;
11+
12+
int m = (s+e)/2;
13+
if (tree[node*2] >= rank) return query(s, m, node*2, rank);
14+
else return query(m+1, e, node*2+1, rank-tree[node*2]);
15+
}
16+
17+
void update(int s, int e, int node, int index, int diff) {
18+
if (e < index || index < s) return;
19+
tree[node] += diff;
20+
if (s == e) return;
21+
22+
int m = (s+e)/2;
23+
update(s, m, node*2, index, diff);
24+
update(m+1, e, node*2+1, index, diff);
25+
}
26+
27+
void solve(){
28+
int N; cin >> N;
29+
30+
for (int i = 0; i < N; i++) {
31+
int a,b;cin >> a>>b;
32+
if (a == 1) {
33+
update(1,MAX,1,b,1);
34+
} else {
35+
int result = query(1, MAX, 1, b);
36+
cout << result << '\n';
37+
update(1,MAX,1,result,-1);
38+
}
39+
}
40+
}
41+
42+
int main()
43+
{
44+
cin.tie(0)->sync_with_stdio(false);
45+
solve();
46+
return 0;
47+
}

1299.cpp

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef long long ll;
4+
struct Node {
5+
int x;
6+
ll weight;
7+
};
8+
struct Edge {
9+
int v,w,idx;
10+
};
11+
struct Compare {
12+
bool operator()(const Node &a, const Node &b) {
13+
return a.weight > b.weight;
14+
}
15+
};
16+
17+
void solve(){
18+
int N, M; cin >> N >> M;N++;
19+
assert(N>1);
20+
assert(M>1);
21+
22+
int S=1,E=N-1;
23+
vector<vector<Edge>> edges(N);
24+
for (int i = 0; i <M;i++) {
25+
int u,v,w; cin >> u >> v >> w;
26+
edges[u].push_back({v,w,i});
27+
edges[v].push_back({u,w,i});
28+
}
29+
30+
vector<vector<pair<int,int>>> parntes(N);
31+
32+
priority_queue<Node, vector<Node>, Compare> q; q.push({S,0});
33+
34+
ll distances[N]; memset(distances, -1, sizeof(distances)); distances[S]=0;
35+
vector<vector<int>> results;
36+
while (q.size()) {
37+
auto [x, weight] = q.top(); q.pop();
38+
for (auto [nx, w, idx] : edges[x]) {
39+
if (distances[nx] > weight + w) parntes[nx].clear();
40+
41+
if (distances[nx] == -1 || distances[nx] > weight + w) {
42+
parntes[nx].push_back({x,idx});
43+
distances[nx] = weight + w;
44+
q.push({nx, distances[nx]});
45+
}
46+
}
47+
}
48+
49+
bool blocked[M];
50+
memset(blocked, 0, sizeof(blocked));
51+
queue<int> q2; q2.push(E);
52+
while (q2.size()) {
53+
auto p = q2.front(); q2.pop();
54+
for (auto [x, idx] : parntes[p]) {
55+
blocked[idx] = true;
56+
q2.push(x);
57+
}
58+
}
59+
60+
61+
memset(distances, -1, sizeof(distances));
62+
distances[S]=0;
63+
q.push({S,0});
64+
while(q.size()) {
65+
auto [x, weight] = q.top(); q.pop();
66+
for (auto [nx, w, idx] : edges[x]) {
67+
if (blocked[idx]) continue;
68+
69+
if (distances[nx] == -1 || distances[nx] > weight+w) {
70+
distances[nx] = weight+w;
71+
q.push({nx, distances[nx]});
72+
}
73+
}
74+
}
75+
76+
cout << distances[E];
77+
}
78+
79+
int main() {
80+
cin.tie(0) -> sync_with_stdio(0);
81+
82+
solve();
83+
84+
return 0;
85+
}

2074.rb

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

2243.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef long long ll;
4+
5+
struct Edge {
6+
int v,w;
7+
};
8+
9+
const ll MOD = 1e9+7;
10+
11+
const int MAX = 1e5;
12+
vector<vector<Edge>> edges(MAX+1);
13+
14+
ll result;
15+
ll dfs(int n, int p) {
16+
ll data = 1;
17+
for (auto [v,w] : edges[n]) {
18+
if (v == p) continue;
19+
ll sub = (dfs(v, n) * w) % MOD;
20+
result = (result + data * sub) % MOD;
21+
data = (data + sub) % MOD;
22+
}
23+
return data;
24+
}
25+
26+
void solve(){
27+
int N; cin >> N;
28+
for (int i = 0; i < N-1; i++) {
29+
int u,v,w;cin>>u>>v>>w;
30+
edges[u].push_back({v,w});
31+
edges[v].push_back({u,w});
32+
}
33+
dfs(1, 0);
34+
cout << result;
35+
}
36+
37+
int main()
38+
{
39+
cin.tie(0)->sync_with_stdio(false);
40+
solve();
41+
return 0;
42+
}

2304.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef long long ll;
4+
5+
void solve(){
6+
int N; cin >> N;
7+
int arr[1001];
8+
for (int i = 0; i <= 1000; i++) arr[i] = 0;
9+
10+
int max_height = 0;
11+
int max_index = 0;
12+
for (int i = 0; i < N; i++) {
13+
int a, b; cin >> a >> b;
14+
arr[a]=b;
15+
if (max_height < b) {
16+
max_height = b;
17+
max_index = a;
18+
}
19+
}
20+
21+
stack<pair<int,int>> st;
22+
for (int i = 1; i < max_index; i++) {
23+
if (!arr[i]) continue;
24+
int height=arr[i];
25+
26+
if (st.empty() || st.top().second < height) st.push({i, height});
27+
}
28+
29+
int result = max_height;
30+
int r = max_index;
31+
while (st.size()) {
32+
auto [x,y] = st.top(); st.pop();
33+
result += (r-x)*y;
34+
r = x;
35+
}
36+
37+
st.push({max_index, max_height});
38+
for (int i = max_index+1; i <= 1000; i++) {
39+
if (!arr[i]) continue;
40+
int height = arr[i];
41+
while (st.size() && st.top().second < height) st.pop();
42+
st.push({i, height});
43+
}
44+
45+
auto [x,y] = st.top(); st.pop();
46+
while (st.size()) {
47+
auto [ax,ay] = st.top(); st.pop();
48+
result += (x-ax)*y;
49+
x=ax;y=ay;
50+
}
51+
cout << result;
52+
}
53+
54+
int main()
55+
{
56+
cin.tie(0)->sync_with_stdio(false);
57+
solve();
58+
return 0;
59+
}

2346.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef long long ll;
4+
5+
void solve(){
6+
int N; cin >> N;
7+
deque<int> dq;
8+
int v[N+1];
9+
for (int i = 1; i <= N; i++) {
10+
cin >> v[i];
11+
dq.push_back(i);
12+
}
13+
14+
for (int i = 0; i < N; i++) {
15+
int x = dq.front();
16+
int y = v[x];
17+
cout << x << ' ';
18+
dq.pop_front();
19+
if (y > 0) {
20+
y--;
21+
while ((y--)>0) {
22+
dq.push_back(dq.front());
23+
dq.pop_front();
24+
}
25+
} else {
26+
while (y++) {
27+
dq.push_front(dq.back());
28+
dq.pop_back();
29+
}
30+
}
31+
}
32+
}
33+
34+
int main()
35+
{
36+
cin.tie(0)->sync_with_stdio(false);
37+
solve();
38+
return 0;
39+
}

0 commit comments

Comments
 (0)