Codeforces Round 988 (Div. 3)

A. Twice

看相同数字出现次数即可

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <bits/stdc++.h>
using namespace std;
#define ls now << 1
#define rs now << 1 | 1
#define endl "\n"
#define lowbit(x) ((x) & (-x))
typedef long long ll;
const int N = 1e5 + 7, mod = 1e9 + 7;
int n;
int a[N];
void solve() {
    map<int,int>vis;
    int ans=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        vis[a[i]]++;
        if(vis[a[i]]>=2)ans++,vis[a[i]]-=2;
    }
    cout<<ans<<endl;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // freopen("..//..//in_out//in.txt", "r", stdin);
    // freopen("..//..//in_out//out.txt", "w", stdout);
    int t = 1;
    cin >> t;
    while (t--) solve();
    return 0;
}

B. Intercepted Inputs

显然是找两个数相乘等于 $n-2$ 即可

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <bits/stdc++.h>
using namespace std;
#define ls now << 1
#define rs now << 1 | 1
#define endl "\n"
#define lowbit(x) ((x) & (-x))
typedef long long ll;
const int N = 2e5 + 7, mod = 1e9 + 7;
int n;
int a[N];
void solve() {
    cin>>n;
    map<int,int>vis;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        vis[a[i]]++;
    }
    int tmp=n-2;
    for(int i=1;i<=n;i++){
        int t=tmp/a[i];
        if(t*a[i]==tmp){
            if(t==a[i]&&vis[a[i]]>=2){
                cout<<t<<" "<<t<<endl;
                return;
            }
            else if(t=a[i]&&vis[t]){
                cout<<a[i]<<" "<<t<<endl;
                return;
            }
        }
    }
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // freopen("..//..//in_out//in.txt", "r", stdin);
    // freopen("..//..//in_out//out.txt", "w", stdout);
    int t = 1;
    cin >> t;
    while (t--) solve();
    return 0;
}

C. Superultra’s Favorite Permutation

可以发现,小于 $5$ 的都不行,然后先按 ${1,3,5,4,2}$ 排,奇数插左边,偶数插右边即可

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <bits/stdc++.h>
using namespace std;
#define ls now << 1
#define rs now << 1 | 1
#define endl "\n"
#define lowbit(x) ((x) & (-x))
typedef long long ll;
const int N = 2e5 + 7, mod = 1e9 + 7;
deque<int>q;
void solve() {
    int n;
    q.clear();
    cin>>n;
    if(n<=4){
        cout<<"-1\n";
        return;
    }
    q.push_back(1);q.push_back(3);q.push_back(5);q.push_back(4);q.push_back(2);
    for(int i=6;i<=n;i++){
        if(i&1)q.push_front(i);
        else q.push_back(i);
    }
    for(auto x:q)cout<<x<<" ";
    cout<<endl;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // freopen("..//..//in_out//in.txt", "r", stdin);
    // freopen("..//..//in_out//out.txt", "w", stdout);
    int t = 1;
    cin >> t;
    while (t--) solve();
    return 0;
}

Sharky Surfing

显然,当前所处位置左侧的加速点都能吃到,只需要保证当前能量足够跳过当前右侧的障碍即可,模拟一遍即可

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <bits/stdc++.h>
using namespace std;
#define ls now << 1
#define rs now << 1 | 1
#define endl "\n"
#define lowbit(x) ((x) & (-x))
typedef long long ll;
const int N = 2e5 + 7, mod = 1e9 + 7;
int n,m,L;
void solve() {
    cin>>n>>m>>L;
    deque<pair<int,int>>block,power;
    for(int i=1;i<=n;i++){
        int a,b;
        cin>>a>>b;
        block.push_back({a,b});
    }
    for(int i=1;i<=m;i++){
        int a,b;
        cin>>a>>b;
        power.push_back({a,b});
    }
    int pos=1,now=1,ans=0;
    multiset<int>s;
    while(block.empty()){
        while(block.empty() && pos >= block.front().second) block.pop_front();
        if (block.empty()) break;
        pos=block.front().first;
        while(power.size()){
            if(power.front().first<pos){
                s.insert(power.front().second);
                power.pop_front();
            }
            else break;
        }
        int len=block.front().second-block.front().first+1;
        while(now<=len&&s.size()){
            ans++;
            now+=*(--s.end());
            s.erase((--s.end()));
        }
        if(now<=len){
            cout<<"-1\n";
            return;
        }
        pos+=now;
    }
    cout<<ans<<endl;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // freopen("..//..//in_out//in.txt", "r", stdin);
    // freopen("..//..//in_out//out.txt", "w", stdout);
    int t = 1;
    cin >> t;
    while (t--) solve();
    return 0;
}

E. Kachina’s Favorite Binary String

题看半天才看懂 $f(l,r)$ 是这个子串中存在 $01$ 子序列的数量
IMPOSSIBLE 的情况就是 $f(1,n)$ 等于 $0$,这时候可能全 $1$ 或全 $0$
有 $n$ 次询问机会,那就可以固定左端点为 $1$,右端点 $2~n$,将对应结果存放起来
因为要找的是 $01$,然后起始连续的 $1$ 都不会对后面造成影响,即我们需要找到第一次 $0$ 出现的位置
对每个位置询问的结果和他前方的比较,如果当前位置比前方大,那么当前位置一定是 $1$,才能使 $f$ 的值增大,反之就是 $0$
接着找到第一次出现 $0$ 的位置,此位置前方有一个片段都是 $1$,片段从 $1$ 到 $i-1-cnt[i]$,这样保证前方的 $01$ 刚好符合题意,前方符合后,后方也会符合

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <bits/stdc++.h>
using namespace std;
#define ls now<<1
#define rs now<<1|1
// #define endl "\n"
#define lowbit(x) ((x)&(-x))
typedef long long ll;
const int N=1e4+7, mod=1e9+7;
int n;
int a[N],b[N];
void solve(){
    cin>>n;
    for(int i=0;i<=n;i++)b[i]=0;
    for(int i=2;i<=n;i++){
        cout<<"? 1 "<<i<<"\n";
        cin>>a[i];
    }
    if(a[n]==0){
        cout<<" IMPOSSIBLE\n";
        cout<<endl;
        return;
    }
    b[1]=0;
    for(int i=2;i<=n;i++){
        if(a[i]>a[i-1])b[i]=1;
    }
    for(int i=2;i<=n;i++){
        if(b[i]){
            for(int j=1;j<=i-1-a[i];j++)b[j]=1;
        }
    }
    cout<<" ";
    for(int i=1;i<=n;i++)cout<<b[i];
    cout<<endl;
}
int main(){
    // ios::sync_with_stdio(0);
    // cin.tie(0);cout.tie(0);
    int t=1;
    cin>>t;
    while(t--)solve();
    return 0;
}
Licensed under CC BY-NC-SA 4.0
最后更新于 Sep 11, 2025 16:27 +0800
发表了95篇文章 · 总计15万2千字
永远相信美好的事情即将发生。
使用 Hugo 构建
主题 StackJimmy 设计