#include <bits/stdc++.h>
using namespace std;
/*
foco no cara da esquerda ativado ou nn
query so na esquerda: desligo
na direita: mudo
*/
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pdd;
const int MAXN = 5e4+10, MAXTT = 2*MAXN;
int s[MAXN], l[MAXN];
bitset<MAXN> r;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, k;
cin >> n >> k;
int a, b;
vector<pii> ord;
for (int i=1;i<=n;i++){
cin >> a >> b;
s[i] = min(a,b), l[i] = max(a,b);
if (a<b) r[i]=1;
ord.emplace_back(l[i], i);
ord.emplace_back(s[i], i);
}
sort(ord.begin(), ord.end());
vector<bitset<MAXN>> es(ord.size()+1, bitset<MAXN>(0)), di(ord.size()+1, bitset<MAXN>(0));
vector<int> count(ord.size());
int cnt = 1;
es[1].flip();
for (int i=0;i<ord.size();i++){
if (i>0 && ord[i].first != ord[i-1].first){
cnt++;
es[cnt] = es[cnt-1], di[cnt]=di[cnt-1];
}
count[i] = cnt;
auto [v, x] = ord[i];
if (v == s[x]){
es[cnt][x] =0;
}else{
es[cnt][x] = 1;
di[cnt][x]=1;
}
}
int t;
for (int i=1;i<=k;i++){
cin >> t;
pii srch = {t+1, -1};
int pos = upper_bound(ord.begin(), ord.end(), srch) - ord.begin() - 1;
if (pos<0) continue;
int v = count[pos];
r = r^di[v];
r = r&es[v];
// cerr << es[v][1] << ' ' << di[v][1] << '\n';
}
long long ss = 0;
for (int i=1;i<=n;i++){
if (r[i] == 1) ss += s[i];
else ss+=l[i];
}
cout << ss << '\n';
return 0;
}
Compilation message
fortune_telling2.cpp: In function 'int main()':
fortune_telling2.cpp:48:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for (int i=0;i<ord.size();i++){
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2896 KB |
Output is correct |
2 |
Correct |
10 ms |
12624 KB |
Output is correct |
3 |
Correct |
19 ms |
24912 KB |
Output is correct |
4 |
Correct |
19 ms |
24912 KB |
Output is correct |
5 |
Correct |
18 ms |
24912 KB |
Output is correct |
6 |
Correct |
20 ms |
24924 KB |
Output is correct |
7 |
Correct |
17 ms |
24912 KB |
Output is correct |
8 |
Correct |
18 ms |
24912 KB |
Output is correct |
9 |
Correct |
18 ms |
24912 KB |
Output is correct |
10 |
Correct |
18 ms |
24912 KB |
Output is correct |
11 |
Correct |
21 ms |
24796 KB |
Output is correct |
12 |
Correct |
17 ms |
25080 KB |
Output is correct |
13 |
Correct |
21 ms |
24912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2896 KB |
Output is correct |
2 |
Correct |
10 ms |
12624 KB |
Output is correct |
3 |
Correct |
19 ms |
24912 KB |
Output is correct |
4 |
Correct |
19 ms |
24912 KB |
Output is correct |
5 |
Correct |
18 ms |
24912 KB |
Output is correct |
6 |
Correct |
20 ms |
24924 KB |
Output is correct |
7 |
Correct |
17 ms |
24912 KB |
Output is correct |
8 |
Correct |
18 ms |
24912 KB |
Output is correct |
9 |
Correct |
18 ms |
24912 KB |
Output is correct |
10 |
Correct |
18 ms |
24912 KB |
Output is correct |
11 |
Correct |
21 ms |
24796 KB |
Output is correct |
12 |
Correct |
17 ms |
25080 KB |
Output is correct |
13 |
Correct |
21 ms |
24912 KB |
Output is correct |
14 |
Correct |
193 ms |
245896 KB |
Output is correct |
15 |
Runtime error |
195 ms |
262144 KB |
Execution killed with signal 9 |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2896 KB |
Output is correct |
2 |
Correct |
10 ms |
12624 KB |
Output is correct |
3 |
Correct |
19 ms |
24912 KB |
Output is correct |
4 |
Correct |
19 ms |
24912 KB |
Output is correct |
5 |
Correct |
18 ms |
24912 KB |
Output is correct |
6 |
Correct |
20 ms |
24924 KB |
Output is correct |
7 |
Correct |
17 ms |
24912 KB |
Output is correct |
8 |
Correct |
18 ms |
24912 KB |
Output is correct |
9 |
Correct |
18 ms |
24912 KB |
Output is correct |
10 |
Correct |
18 ms |
24912 KB |
Output is correct |
11 |
Correct |
21 ms |
24796 KB |
Output is correct |
12 |
Correct |
17 ms |
25080 KB |
Output is correct |
13 |
Correct |
21 ms |
24912 KB |
Output is correct |
14 |
Correct |
193 ms |
245896 KB |
Output is correct |
15 |
Runtime error |
195 ms |
262144 KB |
Execution killed with signal 9 |
16 |
Halted |
0 ms |
0 KB |
- |