# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
197910 |
2020-01-24T06:11:50 Z |
SamAnd |
Fish (IOI08_fish) |
C++17 |
|
1746 ms |
61924 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
int M;
struct ban
{
int x, t;
};
bool operator<(const ban& a, const ban& b)
{
return a.x < b.x;
}
int n, k;
ban a[N];
vector<int> v[N];
int uv[N];
vector<int> uu[N];
int t[N * 4];
void bil(int tl, int tr, int pos)
{
t[pos] = 1;
if (tl == tr)
return;
int m = (tl + tr) / 2;
bil(tl, m, pos * 2);
bil(m + 1, tr, pos * 2 + 1);
}
void ubd(int tl, int tr, int x, int pos)
{
if (tl == tr)
{
++t[pos];
t[pos] %= M;
return;
}
int m = (tl + tr) / 2;
if (x <= m)
ubd(tl, m, x, pos * 2);
else
ubd(m + 1, tr, x, pos * 2 + 1);
t[pos] = (t[pos * 2] * t[pos * 2 + 1]) % M;
}
int qry(int tl, int tr, int l, int r, int pos)
{
if (l > r)
return 1;
if (tl == l && tr == r)
return t[pos];
int m = (tl + tr) / 2;
return (qry(tl, m, l, min(m, r), pos * 2) *
qry(m + 1, tr, max(m + 1, l), r, pos * 2 + 1)) % M;
}
int ver[N];
int main()
{
#ifdef SOMETHING
freopen("input.txt", "r", stdin);
#endif // SOMETHING
scanf("%d%d%d", &n, &k, &M);
for (int i = 1; i <= n; ++i)
{
scanf("%d%d", &a[i].x, &a[i].t);
}
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; ++i)
{
uv[i] = v[a[i].t].size();
v[a[i].t].push_back(i);
}
uv[0] = -1;
for (int i = 1; i <= k; ++i)
{
int l = 1, r = n;
int ans = 0;
while (l <= r)
{
int m = (l + r) / 2;
if (a[m].x * 2 <= a[v[i].back()].x)
{
ans = m;
l = m + 1;
}
else
r = m - 1;
}
uu[ans].push_back(i);
}
int yans = 0;
bil(1, n, 1);
for (int i = 0; i < n; ++i)
{
if (i)
{
ubd(1, n, v[a[i].t].back(), 1);
ver[a[i].t] = i;
}
for (int j = 0; j < uu[i].size(); ++j)
{
int x = uu[i][j];
int l = 1, r = n;
int ans = n + 1;
while (l <= r)
{
int m = (l + r) / 2;
if (a[m].x >= a[v[x][uv[ver[x]] + 1]].x * 2)
{
ans = m;
r = m - 1;
}
else
l = m + 1;
}
l = 1, r = ans - 1;
int ans1 = ans;
while (l <= r)
{
int m = (l + r) / 2;
if (a[m].x >= a[v[x].back()].x)
{
ans1 = m;
r = m - 1;
}
else
l = m + 1;
}
int baz = (qry(1, n, 1, v[x].back() - 1, 1) * qry(1, n, v[x].back() + 1, ans - 1, 1)) % M;
yans = (yans + baz) % M;
baz = (qry(1, n, 1, v[x].back() - 1, 1) * qry(1, n, v[x].back() + 1, ans1 - 1, 1)) % M;
yans = (yans + baz * ((uv[ver[x]] + 1) % M)) % M;
}
}
printf("%d\n", yans);
return 0;
}
Compilation message
fish.cpp: In function 'int main()':
fish.cpp:102:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < uu[i].size(); ++j)
~~^~~~~~~~~~~~~~
fish.cpp:64:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &n, &k, &M);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
fish.cpp:67:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &a[i].x, &a[i].t);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
23800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
23800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
23928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
23988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
23928 KB |
Output is correct |
2 |
Correct |
28 ms |
23928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
23800 KB |
Output is correct |
2 |
Correct |
397 ms |
42380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
23800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
23928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
165 ms |
31896 KB |
Output is correct |
2 |
Correct |
203 ms |
33408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
23928 KB |
Output is correct |
2 |
Correct |
29 ms |
24056 KB |
Output is correct |
3 |
Correct |
29 ms |
24056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
258 ms |
37536 KB |
Output is correct |
2 |
Correct |
421 ms |
43000 KB |
Output is correct |
3 |
Correct |
418 ms |
43204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
353 ms |
38760 KB |
Output is correct |
2 |
Correct |
434 ms |
44040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
239 ms |
37988 KB |
Output is correct |
2 |
Correct |
454 ms |
43620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
445 ms |
37900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
527 ms |
39320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
492 ms |
37752 KB |
Output is correct |
2 |
Correct |
783 ms |
47352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
905 ms |
42772 KB |
Output is correct |
2 |
Correct |
694 ms |
43512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
698 ms |
45984 KB |
Output is correct |
2 |
Correct |
867 ms |
48512 KB |
Output is correct |
3 |
Correct |
812 ms |
51492 KB |
Output is correct |
4 |
Correct |
859 ms |
48404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1118 ms |
45780 KB |
Output is correct |
2 |
Correct |
1409 ms |
60900 KB |
Output is correct |
3 |
Correct |
1466 ms |
61924 KB |
Output is correct |
4 |
Correct |
1746 ms |
59760 KB |
Output is correct |