Submission #119701

# Submission time Handle Problem Language Result Execution time Memory
119701 2019-06-21T23:07:16 Z eriksuenderhauf Pairs (IOI07_pairs) C++11
60 / 100
42 ms 2812 KB
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAX2 = 263000 + 5;
const double eps = 1e-9;
int b, n, d, m;
int BIT2[MAX2];

void upd2(int ind, int v) {
	ind++;
	while (ind < MAX2) {
		BIT2[ind] += v;
		ind += ind & -ind;
	}
}

int qry2(int ind) {
	ind++;
	int ret = 0;
	while (ind > 0) {
		ret += BIT2[ind];
		ind -= ind & -ind;
	}
	return ret;
}

ll qry2(int l, int r) {
	return qry2(r) - qry2(l - 1);
}

int main() {
	scanf("%d %d %d %d", &b, &n, &d, &m);
	ll ans = 0;
	if (b == 1) {
		vector<int> a;
		a.resize(n);
		for (int i = 0; i < n; i++)
			ni(a[i]);
		sort(a.begin(), a.end());
		int j = 0;
		for (int i = 0; i < n; i++) {
			while (j <= i && a[i]-a[j] > d) j++;
			ans += (ll) (i - j);
		}
	} else if (b == 2) {
		vector<pii> a;
		a.resize(n);
		for (int i = 0; i < n; i++) {
			scanf("%d %d", &a[i].fi, &a[i].se);
			a[i] = mp(a[i].fi-a[i].se, a[i].fi+a[i].se);
		}
		sort(a.begin(), a.end());
		int j = 0; 
		for (int i = 0; i < n; i++) {
			while (j <= i && a[i].fi-a[j].fi > d)
				upd2(a[j++].se, -1);
			ans += qry2(a[i].se - d, a[i].se + d);
			upd2(a[i].se, 1);
		}
	} else {
		
	}
	prl(ans);
    return 0;
}

Compilation message

pairs.cpp: In function 'int main()':
pairs.cpp:63:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d %d", &b, &n, &d, &m);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pairs.cpp:9:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define ni(n) scanf("%d", &(n))
               ~~~~~^~~~~~~~~~~~
pairs.cpp:69:4: note: in expansion of macro 'ni'
    ni(a[i]);
    ^~
pairs.cpp:80:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d %d", &a[i].fi, &a[i].se);
    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 1152 KB Output is correct
2 Correct 17 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 1792 KB Output is correct
2 Correct 23 ms 1536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 1564 KB Output is correct
2 Correct 25 ms 1564 KB Output is correct
3 Correct 23 ms 1664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 896 KB Output is correct
2 Correct 3 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 1784 KB Output is correct
2 Correct 32 ms 1664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 1916 KB Output is correct
2 Correct 38 ms 1912 KB Output is correct
3 Correct 37 ms 2044 KB Output is correct
4 Correct 37 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 2808 KB Output is correct
2 Correct 42 ms 2808 KB Output is correct
3 Correct 39 ms 2808 KB Output is correct
4 Correct 40 ms 2812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -