Submission #62795

# Submission time Handle Problem Language Result Execution time Memory
62795 2018-07-30T05:06:05 Z BBang3 None (KOI18_XCorr) C++14
100 / 100
280 ms 116224 KB
#include <cstdio>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

int N, M;
long long partsum[300000 + 5];
vector<pair<int, int> > A;
vector<pair<int, int> > B;
// first : index, second : num
int getapos(int idx)
{
	
	int left = 1, right = M, mid, ret = -1;
	while (left <= right)
	{
		mid = (left + right) / 2;

		if (B[mid].first >= idx)
		{
			right = mid - 1;
			ret = mid;
		}
		else left = mid + 1;
	}

	return ret;
}

int getbpos(int idx)
{

	int left = 1, right = M, mid, ret = -1;
	while (left <= right)
	{
		mid = (left + right) / 2;

		if (B[mid].first <= idx)
		{
			left = mid + 1;
			ret = mid;
		}
		else
		{
			right = mid - 1;
		}
	}

	return ret;
}

int main()
{
	scanf("%d", &N);
	A.resize(N + 5);
	for (int i = 1; i <= N; i++)
	{
		scanf("%d %d", &A[i].first, &A[i].second);
	}
	scanf("%d", &M);
	B.resize(M + 5);
	for (int i = 1; i <= M; i++)
	{
		scanf("%d %d", &B[i].first, &B[i].second);
	}
	sort(B.begin() + 1, B.begin() + M + 1);
	for (int i = 1; i <= M; i++)
		partsum[i] = partsum[i - 1] + B[i].second;
	int a, b;
	scanf("%d %d", &a, &b);
	long long ans = 0;
	for (int i = 1; i <= N; i++)
	{
		int curidx = A[i].first, curnum = A[i].second;

		int s = getapos(curidx + a), e = getbpos(curidx + b);

		if (s == -1 || e == -1) continue;
		ans += (partsum[e] - partsum[s - 1]) * (long long)curnum;
	}
	printf("%lld",ans);
	return 0;
}

Compilation message

XCorr.cpp: In function 'int main()':
XCorr.cpp:55:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
XCorr.cpp:59:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &A[i].first, &A[i].second);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
XCorr.cpp:61:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &M);
  ~~~~~^~~~~~~~~~
XCorr.cpp:65:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &B[i].first, &B[i].second);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
XCorr.cpp:71:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &a, &b);
  ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 380 KB Output is correct
2 Correct 5 ms 540 KB Output is correct
3 Correct 5 ms 664 KB Output is correct
4 Correct 4 ms 768 KB Output is correct
5 Correct 3 ms 840 KB Output is correct
6 Correct 5 ms 840 KB Output is correct
7 Correct 5 ms 840 KB Output is correct
8 Correct 6 ms 876 KB Output is correct
9 Correct 4 ms 1064 KB Output is correct
10 Correct 6 ms 1064 KB Output is correct
11 Correct 2 ms 1064 KB Output is correct
12 Correct 6 ms 1064 KB Output is correct
13 Correct 5 ms 1228 KB Output is correct
14 Correct 2 ms 1228 KB Output is correct
15 Correct 7 ms 1228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 380 KB Output is correct
2 Correct 5 ms 540 KB Output is correct
3 Correct 5 ms 664 KB Output is correct
4 Correct 4 ms 768 KB Output is correct
5 Correct 3 ms 840 KB Output is correct
6 Correct 5 ms 840 KB Output is correct
7 Correct 5 ms 840 KB Output is correct
8 Correct 6 ms 876 KB Output is correct
9 Correct 4 ms 1064 KB Output is correct
10 Correct 6 ms 1064 KB Output is correct
11 Correct 2 ms 1064 KB Output is correct
12 Correct 6 ms 1064 KB Output is correct
13 Correct 5 ms 1228 KB Output is correct
14 Correct 2 ms 1228 KB Output is correct
15 Correct 7 ms 1228 KB Output is correct
16 Correct 132 ms 8892 KB Output is correct
17 Correct 6 ms 8892 KB Output is correct
18 Correct 247 ms 18788 KB Output is correct
19 Correct 6 ms 18788 KB Output is correct
20 Correct 5 ms 18788 KB Output is correct
21 Correct 4 ms 18788 KB Output is correct
22 Correct 3 ms 18788 KB Output is correct
23 Correct 5 ms 18788 KB Output is correct
24 Correct 251 ms 24320 KB Output is correct
25 Correct 250 ms 31812 KB Output is correct
26 Correct 256 ms 38244 KB Output is correct
27 Correct 6 ms 38244 KB Output is correct
28 Correct 6 ms 38244 KB Output is correct
29 Correct 4 ms 38244 KB Output is correct
30 Correct 235 ms 45100 KB Output is correct
31 Correct 5 ms 45100 KB Output is correct
32 Correct 266 ms 50988 KB Output is correct
33 Correct 248 ms 57896 KB Output is correct
34 Correct 99 ms 58408 KB Output is correct
35 Correct 3 ms 58408 KB Output is correct
36 Correct 208 ms 67624 KB Output is correct
37 Correct 69 ms 67624 KB Output is correct
38 Correct 5 ms 67624 KB Output is correct
39 Correct 209 ms 75628 KB Output is correct
40 Correct 5 ms 75628 KB Output is correct
41 Correct 3 ms 75628 KB Output is correct
42 Correct 4 ms 75628 KB Output is correct
43 Correct 2 ms 75628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 380 KB Output is correct
2 Correct 5 ms 540 KB Output is correct
3 Correct 5 ms 664 KB Output is correct
4 Correct 4 ms 768 KB Output is correct
5 Correct 3 ms 840 KB Output is correct
6 Correct 5 ms 840 KB Output is correct
7 Correct 5 ms 840 KB Output is correct
8 Correct 6 ms 876 KB Output is correct
9 Correct 4 ms 1064 KB Output is correct
10 Correct 6 ms 1064 KB Output is correct
11 Correct 2 ms 1064 KB Output is correct
12 Correct 6 ms 1064 KB Output is correct
13 Correct 5 ms 1228 KB Output is correct
14 Correct 2 ms 1228 KB Output is correct
15 Correct 7 ms 1228 KB Output is correct
16 Correct 132 ms 8892 KB Output is correct
17 Correct 6 ms 8892 KB Output is correct
18 Correct 247 ms 18788 KB Output is correct
19 Correct 6 ms 18788 KB Output is correct
20 Correct 5 ms 18788 KB Output is correct
21 Correct 4 ms 18788 KB Output is correct
22 Correct 3 ms 18788 KB Output is correct
23 Correct 5 ms 18788 KB Output is correct
24 Correct 251 ms 24320 KB Output is correct
25 Correct 250 ms 31812 KB Output is correct
26 Correct 256 ms 38244 KB Output is correct
27 Correct 6 ms 38244 KB Output is correct
28 Correct 6 ms 38244 KB Output is correct
29 Correct 4 ms 38244 KB Output is correct
30 Correct 235 ms 45100 KB Output is correct
31 Correct 5 ms 45100 KB Output is correct
32 Correct 266 ms 50988 KB Output is correct
33 Correct 248 ms 57896 KB Output is correct
34 Correct 99 ms 58408 KB Output is correct
35 Correct 3 ms 58408 KB Output is correct
36 Correct 208 ms 67624 KB Output is correct
37 Correct 69 ms 67624 KB Output is correct
38 Correct 5 ms 67624 KB Output is correct
39 Correct 209 ms 75628 KB Output is correct
40 Correct 5 ms 75628 KB Output is correct
41 Correct 3 ms 75628 KB Output is correct
42 Correct 4 ms 75628 KB Output is correct
43 Correct 2 ms 75628 KB Output is correct
44 Correct 119 ms 76716 KB Output is correct
45 Correct 7 ms 76716 KB Output is correct
46 Correct 228 ms 86500 KB Output is correct
47 Correct 5 ms 86500 KB Output is correct
48 Correct 167 ms 90964 KB Output is correct
49 Correct 70 ms 91732 KB Output is correct
50 Correct 5 ms 91732 KB Output is correct
51 Correct 4 ms 91732 KB Output is correct
52 Correct 3 ms 91732 KB Output is correct
53 Correct 6 ms 91732 KB Output is correct
54 Correct 248 ms 101312 KB Output is correct
55 Correct 237 ms 108852 KB Output is correct
56 Correct 209 ms 116032 KB Output is correct
57 Correct 217 ms 116076 KB Output is correct
58 Correct 252 ms 116112 KB Output is correct
59 Correct 6 ms 116112 KB Output is correct
60 Correct 3 ms 116112 KB Output is correct
61 Correct 5 ms 116112 KB Output is correct
62 Correct 256 ms 116112 KB Output is correct
63 Correct 207 ms 116112 KB Output is correct
64 Correct 4 ms 116112 KB Output is correct
65 Correct 252 ms 116112 KB Output is correct
66 Correct 206 ms 116224 KB Output is correct
67 Correct 253 ms 116224 KB Output is correct
68 Correct 6 ms 116224 KB Output is correct
69 Correct 227 ms 116224 KB Output is correct
70 Correct 104 ms 116224 KB Output is correct
71 Correct 245 ms 116224 KB Output is correct
72 Correct 219 ms 116224 KB Output is correct
73 Correct 102 ms 116224 KB Output is correct
74 Correct 2 ms 116224 KB Output is correct
75 Correct 240 ms 116224 KB Output is correct
76 Correct 69 ms 116224 KB Output is correct
77 Correct 4 ms 116224 KB Output is correct
78 Correct 272 ms 116224 KB Output is correct
79 Correct 3 ms 116224 KB Output is correct
80 Correct 6 ms 116224 KB Output is correct
81 Correct 3 ms 116224 KB Output is correct
82 Correct 280 ms 116224 KB Output is correct
83 Correct 3 ms 116224 KB Output is correct
84 Correct 3 ms 116224 KB Output is correct
85 Correct 249 ms 116224 KB Output is correct