Skip to content

Instantly share code, notes, and snippets.

@ro0opf
Created February 27, 2019 07:21
Show Gist options
  • Save ro0opf/2c1706808a79d7a1f9407ca9b92641be to your computer and use it in GitHub Desktop.
Save ro0opf/2c1706808a79d7a1f9407ca9b92641be to your computer and use it in GitHub Desktop.
2143
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cstring>
#include <map>
#include <stack>
#include <functional>
#include <set>
#include <math.h>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <cstdio>
#include <sstream>
#define ll long long int
#define ld long double
#define fr(i, a, b) for(int i = a; i < b; i++)
#define frb(i, a, b) for(int i = a; i >= b; i--)
#define sq(x) ((x) * (x))
#define PI ( acos(-1.0) )
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define px first
#define py second
using namespace std;
typedef vector<vector<int>> mat;
ll T;
ll asz, bsz;
ll dta[1001], dtb[1001];
void _init() {
cin >> T;
cin >> asz;
ll t;
cin >> t;
dta[1] = t;
fr(i, 2, asz+1) {
cin >> t;
dta[i] = dta[i - 1] + t;
}
cin >> bsz;
cin >> t;
dtb[1] = t;
fr(i, 2, bsz+1) {
cin >> t;
dtb[i] = dtb[i - 1] + t;
}
}
ll get_a(ll l, ll h) {
return dta[h] - dta[l - 1];
}
ll get_b(ll l, ll h) {
return dtb[h] - dtb[l - 1];
}
void _solve() {
ll res = 0;
unordered_map<ll, ll> mym;
fr(i, 1, asz + 1) {
fr(j, i, asz+1) {
mym[get_a(i, j)]++;
}
}
fr(i, 1, bsz + 1) {
fr(j, i, bsz + 1) {
res += mym[T - get_b(i, j)];
}
}
cout << res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
_init();
_solve();
//system("pause");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment