比赛 |
2025.9.13 |
评测结果 |
AAAAEAATTTTTEEEEEEEE |
题目名称 |
The Best Subsequence |
最终得分 |
30 |
用户昵称 |
淮淮清子 |
运行时间 |
16.849 s |
代码语言 |
C++ |
内存使用 |
20.81 MiB |
提交时间 |
2025-09-13 11:27:36 |
显示代码纯文本
#include<iostream>
#include<algorithm>
using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 1e7 + 10;
int bit[MAXN];
int a_1[MAXN], a_0[MAXN];
int id[MAXN];
int N, M, Q;
int l, r, k;
int main(){
freopen("Subsequence.in", "r", stdin);
freopen("Subsequence.out", "w", stdout);
ios::sync_with_stdio(0); cin.tie(0);
cin >> N >> M >> Q;
for(int i = 1;i <= N;i ++) bit[i] = 0;
while(M --){
int l, r;
cin >> l >> r;
for(int i = l;i <= r;i ++){
bit[i] ^= 1;
}
}
while(Q --){
cin >> l >> r >> k;
int c1 = 0, c0 = 0;
for(int i = l;i <= r;i ++){
if(bit[i]) a_1[c1 ++] = i - l + 1;
else a_0[c0 ++] = i - l + 1;
}
int cnt = 0;
//cout << c1 << ' ' << c2 << '\n'
if(c1 >= k){
for(int i = 0;i < k;i ++){
id[cnt ++] = a_1[i];
}
}
else{
for(int i = 0;i < c1;i ++){
id[cnt ++] = a_1[i];
}
int tmp = k - c1;
for(int i = c0 - tmp;i < c0;i ++){
id[cnt ++] = a_0[i];
}
}
sort(id, id + cnt);
// for(int x : id) cout << x << ' ';
long long res = 0;
for(int i = 0;i < cnt;i ++){
res = (res * 2 + bit[l + id[i] - 1]) % MOD;
}
cout << res << '\n';
}
return 0;
}