当前位置:网站首页>AtCoder Beginner Contest 260 - C, D, E
AtCoder Beginner Contest 260 - C, D, E
2022-07-22 02:02:00 【Dimple】
https://atcoder.jp/contests/abc260/tasks
E - At Least One
The question
Given N N N Pairs of numbers ( A 1 , B 1 ) , ( A 2 , B 2 ) , … , ( A N , B N ) \left(A_{1}, B_{1}\right),\left(A_{2}, B_{2}\right), \ldots,\left(A_{N}, B_{N}\right) (A1,B1),(A2,B2),…,(AN,BN)
For all i i i, All satisfied with 1 ≤ A i < B i ≤ M 1 \leq A_{i}<B_{i} \leq M 1≤Ai<Bi≤M.
If in a continuous interval [ l , r ] [l, r] [l,r] in , N N N The number is right A i A_i Ai and B i B_i Bi There is at least one , So this continuous interval is Good interval
.
ask , The length is 1 , 2 , . . . , M 1,2,...,M 1,2,...,M Of Good interval
How many of them are there ?
- 1 ≤ N ≤ 2 × 1 0 5 1 \leq N \leq 2 \times 10^{5} 1≤N≤2×105
- 2 ≤ M ≤ 2 × 1 0 5 2 \leq M \leq 2 \times 10^{5} 2≤M≤2×105
- 1 ≤ A i < B i ≤ M 1 \leq A_{i}<B_{i} \leq M 1≤Ai<Bi≤M
Ideas
Will number i Are hung separately Ai and Bi below , That is, for a number , It corresponds to multiple numbers , altogether M Number .
If a continuous number , Satisfy n All numbers have appeared , Then this number is good .
If a good interval is determined from l To r, Then its outward extension range is also good .
Traverse each position from front to back i
, You can use the sliding window to maintain the minimum satisfied interval every time [l, r]
, Then the length of this interval is the shortest interval , And all the intervals that extend to the left and right of this interval are satisfied .
To prevent interval repetition , This interval only extends to the left , It is satisfied to extend to the first position .
in other words , length r-l+1
To length i
The interval length of is satisfied , The number of answers of these lengths is +1( Differential realization ).
All in all M A place , Each number can enter and leave the team at most twice , The total complexity is O ( N + M ) O(N+M) O(N+M).
Code
#include<bits/stdc++.h>
using namespace std;
#define Ios ios::sync_with_stdio(false),cin.tie(0)
const int N = 200010, mod = 1e9+7;
int T, n, m;
int a[N], ans[N];
int q[N], mp[N];
vector<int> v[N];
bool check(int i)
{
for(int x : v[i])
{
if(mp[x] == 1) return 0;
}
return 1;
}
signed main(){
Ios;
cin >> n >> m;
for(int i=1;i<=n;i++){
int x, y; cin >> x >> y;
v[x].push_back(i);
v[y].push_back(i);
}
int sum = 0;
int hh = 0, tt = -1;
for(int i=1;i<=m;i++)
{
q[++tt] = i;
for(int x : v[i]){
mp[x]++;
if(mp[x] == 1) sum++;
}
while(hh <= tt && check(q[hh])){
for(int x : v[q[hh]]) mp[x]--;
hh++;
}
if(sum == n) ans[tt-hh+1]++, ans[i+1]--;
}
for(int i=1;i<=m;i++) ans[i] += ans[i-1], cout << ans[i] << " ";
return 0;
}
D - Draw Your Cards
The question
Yes N The opposite card , Each card has value X i X_i Xi, Different from each other .
Take one from the top each time , Assuming that X, Put it in the pile of cards that have been removed .
- Find the first card on the top of all stacks that is greater than or equal to X The card of , Put it on it .
- If you can't find it, make another pile .
- If the number of cards in a deck equals K 了 , Then this stack of cards will be cleared .
ask , Each card is cleared after several card taking operations ? If not cleared , Output -1.
1 ≤ K ≤ N ≤ 2 × 1 0 5 1 \leq K \leq N \leq 2 \times 10^{5} 1≤K≤N≤2×105
Ideas
Just simulate according to the meaning of the title , You can number the existing deck , Then record the stack number of each card taken out .
Put the top card on set in , It is convenient for two points to find the corresponding stack .
Be careful K = 1 The situation of .
Code
#include<bits/stdc++.h>
using namespace std;
#define Ios ios::sync_with_stdio(false),cin.tie(0)
const int N = 200010, mod = 1e9+7;
int T, n, m;
int a[N];
vector<int> v[N];
int pos[N], ans[N];
signed main(){
Ios;
cin >> n >> m;
set<int> st;
int cnt = 0;
for(int i=1;i<=n;i++)
{
int x; cin >> x;
auto it = st.lower_bound(x);
if(it != st.end())
{
int tx = *it;
pos[x] = pos[tx];
st.erase(tx);
v[pos[tx]].push_back(x);
if(v[pos[tx]].size() == m)
{
for(int t : v[pos[tx]])
ans[t] = i;
}
else st.insert(x);
}
else{
pos[x] = ++cnt;
v[cnt].push_back(x);
if(m == 1) ans[x] = i;
else st.insert(x);
}
}
for(int i=1;i<=n;i++)
if(ans[i]) cout << ans[i] << "\n";
else cout << "-1\n";
return 0;
}
C - Changing Jewels
The question
Given X, Y And a grade of n Ruby .
ask , After the following transformation , The maximum level you can get is 1 Sapphire ?
- red n → red ( n − 1 ) + X ∗ blue n red n → red (n-1) + X * blue n red n→ red (n−1)+X∗ blue n;
- blue n → red ( n − 1 ) + Y ∗ blue ( n − 1 ) blue n → red (n-1) + Y * blue (n-1) blue n→ red (n−1)+Y∗ blue (n−1);
1 ≤ n ≤ 10 1 \leq n \leq 10 1≤n≤10, 1 < X < 5 1<X<5 1<X<5, 1 ≤ Y ≤ 5 1 \leq Y \leq 5 1≤Y≤5
Ideas
Direct two recursions to engage with each other RE 了 ..
Then take all blue n All of them are transformed first , All become red and The last number , Then a recursive red That's it .
From the second transformation :
blue n → red ( n − 1 ) + Y ∗ red ( n − 2 ) + Y 2 ∗ red ( n − 3 ) + . . . + Y n − 1 blue n → red (n-1) + Y* red (n-2) + Y^2* red (n-3) + ... + Y^{n-1} blue n→ red (n−1)+Y∗ red (n−2)+Y2∗ red (n−3)+...+Yn−1
that
red n → red ( n − 1 ) + X ∗ [ red ( n − 1 ) + Y ∗ red ( n − 2 ) + Y 2 ∗ red ( n − 3 ) + . . . + Y n − 1 ] red n → red (n-1) + X *[ red (n-1) + Y* red (n-2) + Y^2* red (n-3) + ... + Y^{n-1}] red n→ red (n−1)+X∗[ red (n−1)+Y∗ red (n−2)+Y2∗ red (n−3)+...+Yn−1].
Code
#include<bits/stdc++.h>
using namespace std;
#define Ios ios::sync_with_stdio(false),cin.tie(0)
const int N = 200010, mod = 1e9+7;
int T, n, m;
int a[N];
int x,y;
int red(int n)
{
if(n < 2) return 0;
int sum = 0;
sum += red(n-1);
int cnt = 0;
for(int i = n-1; i>=0;i--)
{
sum += x*(pow(y, cnt++) * red(i));
}
sum += x * pow(y, n-1);
return sum;
}
signed main(){
Ios;
cin >> n >> x >> y;
cout << red(n);
return 0;
}
边栏推荐
猜你喜欢
Jugement des chaînes vides dans Oracle
谷歌展示 Chrome 浏览器图标废案,曾打算做成小火箭
腾讯 Techo Hub 2022 年首站落地福州|723,与开发者们探讨工业数字化!
[paper reading] deep video analog detection: opportunities and challenges
利用正则回溯最大次数上限进行绕过
NepCTF2022 WP
「华流才是顶流」?分享你心目中的YYDS
M carry out DS-CDMA modeling in Simulink, and then call Simulink model through MATLAB to simulate the bit error rate
Pytorch common code snippet collection
安全之路 —— 单管道反向连接后门解析
随机推荐
SQL164 2021年11月每天新用户的次日留存率
3625. 幂次方
[deep learning notes] attention mechanism
TCP的滑动窗口、单例模式(懒汉饿汉)双检锁/双重校验锁(DCL,即 double-checked locking)
clip:learning transferable visual models from natural language supervision
M using Verilog to develop GMSK modulator based on FPGA under ISE platform
解决Error L6218E Undefined symbol XXX....问题
ssh方式登录huawei设备
Add two numbers leecode2
Compare the market Taobao short video tools / software, and analyze the future trend of Taobao short video
使用修改为jmp指令的方式hook 32位函数
沟通 节选自《闻缺陷则喜》(此书可免费下载)
Oracle中對空字符串的判斷
玫瑰
VALDO2021——血管病变检测挑战赛之血管间隙分割(三)
When xshell connects, it displays "the server sent an unexpected packet. Received:3, expected:20
2022-7-17 FTP client project implementation - Summary
Dynamic planning example diver
LeetCode 146:LRU 缓存
rose