#include <bits/stdc++.h>
using namespace std;
const int MAXN=100000;
long long k, n, pradSuma=0, suma=0;
char a[MAXN], b[MAXN];
long long x[MAXN], y[MAXN];
vector<tuple<long long, long long, long long>> keliai;
long long dPtr=0;
long long dKairej=0, dDesinej;
void tinkintDesine(long long id1, long long id2)
{
while (dKairej<dDesinej)
{
long long pradPos=get<0>(keliai[dPtr]);
dPtr++;
suma-=2ll*(get<0>(keliai[dPtr])-pradPos)*(dDesinej-dKairej);
if (get<1>(keliai[dPtr])==0)
dDesinej--;
else
dKairej++;
}
}
int main()
{
cin>>k>>n;
for (int i=0; i<n; i++)
{
cin>>a[i]>>x[i]>>b[i]>>y[i];
if (x[i]>y[i])
swap(x[i], y[i]);
pradSuma+=y[i]-x[i];
if (a[i]!=b[i])
{
pradSuma++;
keliai.push_back(make_tuple(x[i], 0, i));
keliai.push_back(make_tuple(y[i], 1, i));
}
}
keliai.push_back(make_tuple(0, 0, 0));
sort(keliai.begin(), keliai.end());
for (int i=0; i<n; i++)
if (a[i]!=b[i])
suma+=2ll*x[i];
dDesinej=keliai.size()/2;
tinkintDesine(-1, -1);
if (k==1)
{
cout<<pradSuma+suma<<endl;
return 0;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
552 KB |
Output is correct |
6 |
Correct |
1 ms |
568 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
35 ms |
8104 KB |
Output is correct |
13 |
Correct |
61 ms |
7844 KB |
Output is correct |
14 |
Correct |
46 ms |
7884 KB |
Output is correct |
15 |
Correct |
39 ms |
4272 KB |
Output is correct |
16 |
Correct |
49 ms |
7884 KB |
Output is correct |
17 |
Correct |
65 ms |
7760 KB |
Output is correct |
18 |
Correct |
67 ms |
8292 KB |
Output is correct |
19 |
Correct |
63 ms |
7704 KB |
Output is correct |
20 |
Correct |
57 ms |
7884 KB |
Output is correct |
21 |
Correct |
59 ms |
9152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |