Submission #159073

#TimeUsernameProblemLanguageResultExecution timeMemory
159073dennisstarXCorr (KOI18_XCorr)C++11
100 / 100
198 ms25808 KiB
#include <bits/stdc++.h>
#define fi first
#define se second
#define ryan bear
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;

vector<pll> ar1, ar2;
int fr, re; int N, M, a, b;
ll ans, now;

int main()
{
	int x, y, i;
	scanf("%d", &N);
	for (i=0; i<N; i++) {
		scanf("%d %d", &x, &y);
		ar1.push_back({x,y});
	}
	scanf("%d", &M);
	for (i=0; i<M; i++) {
		scanf("%d %d", &x, &y);
		ar2.push_back({x,y});
	}
	sort(ar1.begin(), ar1.end());
	sort(ar2.begin(), ar2.end());
	scanf("%d %d", &a, &b);
	for (i=0; i<M; i++) if (ar2[i].fi>=ar1[0].fi+a) break;
	fr=i;
	for (i=0; i<M; i++) if (ar2[i].fi>ar1[0].fi+b) break;
	re=i;
	for (i=fr; i<re; i++) now+=ar2[i].se;
	for (i=0; i<N; i++) {
		while (fr<M && ar2[fr].fi<ar1[i].fi+a) {
			now-=ar2[fr].se;
			fr++;
		}
		while (re<M && ar2[re].fi<=ar1[i].fi+b) {
			now+=ar2[re].se;
			re++;
		}
		ans+=now*ar1[i].se;
	}
	printf("%lld", ans);
	return 0;
}

Compilation message (stderr)

XCorr.cpp: In function 'int main()':
XCorr.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
XCorr.cpp:20:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &x, &y);
   ~~~~~^~~~~~~~~~~~~~~~~
XCorr.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &M);
  ~~~~~^~~~~~~~~~
XCorr.cpp:25:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &x, &y);
   ~~~~~^~~~~~~~~~~~~~~~~
XCorr.cpp:30: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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...