# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
653086 |
2022-10-25T15:56:49 Z |
Vladth11 |
Fish (IOI08_fish) |
C++14 |
|
710 ms |
24444 KB |
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <algorithm>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
const int bSize = 11;
const int bits = 17;
const int NMAX = 500001;
int MOD;
class AINT {
public:
int aint[NMAX * 4];
void init() {
for(int i = 0; i < NMAX * 4; i++)
aint[i] = 1;
}
void add(int node, int st, int dr, int l, int x) {
if(st == dr) {
aint[node] += x;
aint[node] = max(aint[node], 1);
return;
}
int mid = (st + dr) / 2;
if(l <= mid) {
add(node * 2, st, mid, l, x);
} else {
add(node * 2 + 1, mid + 1, dr, l, x);
}
aint[node] = aint[node * 2] * aint[node * 2 + 1];
aint[node] %= MOD;
}
void update(int node, int st, int dr, int l, int x) {
if(st == dr) {
aint[node] = x;
aint[node] = max(aint[node], 1);
return;
}
int mid = (st + dr) / 2;
if(l <= mid) {
update(node * 2, st, mid, l, x);
} else {
update(node * 2 + 1, mid + 1, dr, l, x);
}
aint[node] = aint[node * 2] * aint[node * 2 + 1];
aint[node] %= MOD;
}
} aint, banned;
int imp[NMAX];
int col[NMAX];
int maxi[NMAX];
pii v[NMAX];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, k, i;
cin >> n >> k >> MOD;
for(i = 1; i <= n; i++) {
cin >> v[i].first >> v[i].second;
}
sort(v + 1, v + n + 1);
for(i = n; i >= 1; i--) {
if(!col[v[i].second]) {
imp[i] = 1;
}
col[v[i].second]++;
}
aint.init();
banned.init();
for(i = 1; i <= n; i++){
maxi[i] = col[i];
aint.update(1, 1, n, i, col[i] + 1);
banned.update(1, 1, n, i, col[i] + 1);
}
int dr = n + 1, st = n;
ll rez = 0;
for(i = n; i >= 1; i--){
while(st >= 1 && v[st].first * 2 > v[i].first){
aint.add(1, 1, n, v[st].second, -1);
banned.add(1, 1, n, v[st].second, -1);
col[v[st].second]--;
st--;
}
if(i == n){
for(int j = 1; j <= n; j++){
maxi[j] = col[j];
}
}
if(imp[i]){
rez += banned.aint[1];
rez %= MOD;
if(v[i].first * 2 > v[n].first && i != n && maxi[v[i].second] == col[v[i].second]){
aint.update(1, 1, n, v[i].second, 1);
rez += aint.aint[1];
aint.update(1, 1, n, v[i].second, col[v[i].second] + 1);
rez %= MOD;
}
}
//aint.update(1, 1, n, v[i].second, 1);
banned.update(1, 1, n, v[i].second, 1);
}
cout << rez;
return 0;
}
Compilation message
fish.cpp: In function 'int main()':
fish.cpp:89:9: warning: unused variable 'dr' [-Wunused-variable]
89 | int dr = n + 1, st = n;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
15956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
15892 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
15956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
15972 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
16008 KB |
Output is correct |
2 |
Incorrect |
9 ms |
15956 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
15920 KB |
Output is correct |
2 |
Incorrect |
532 ms |
21840 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
15956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
15956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
202 ms |
18344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
15956 KB |
Output is correct |
2 |
Correct |
14 ms |
16228 KB |
Output is correct |
3 |
Incorrect |
10 ms |
15956 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
336 ms |
19632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
487 ms |
22516 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
306 ms |
20744 KB |
Output is correct |
2 |
Incorrect |
566 ms |
22192 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
503 ms |
21748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
583 ms |
22568 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
469 ms |
21016 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
571 ms |
23360 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
503 ms |
23160 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
710 ms |
24444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |