2 2 2 1 2 1 1 1 1 1 2 2 1 2 2 2 2 2 1 1 1 1 2 2 1 2 2
Yes No YesHintHuge input, scanf recommended.
两种解法:
I.
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define N 100000 + 10 int n, m, k, q; struct Tree { int c[N], maxn; void init(int n) { maxn = n; for (int i = 0; i <= n; i++)c[i] = 0; } int lowbit(int x) { return x&-x; } int sum(int x) { int ans = 0; while (x)ans += c[x], x -= lowbit(x); return ans; } void update(int pos, int val) { while (pos <= maxn)c[pos] += val, pos += lowbit(pos); } }TX, TY; int vx[N], vy[N]; int main() { int T; scanf("%d", &T); while(T--) { memset(vx, 0, sizeof vx); memset(vy, 0, sizeof vy); scanf("%d%d%d%d", &n, &m, &k, &q); TX.init(n); TY.init(m); int x, y; for(int i = 0; i < k; i++) { scanf("%d%d", &x, &y); if(!vx[x]) { TX.update(x, 1); vx[x] = 1; } if(!vy[y]) { TY.update(y, 1); vy[y] = 1; } } int x1, y1, flag; for(int i = 0; i < q; i++) { scanf("%d%d%d%d", &x, &y, &x1, &y1); if((TX.sum(x1) - TX.sum(x - 1) == (x1 - x + 1)) || (TY.sum(y1) - TY.sum(y - 1) == (y1 - y + 1))) printf("Yes\n"); else printf("No\n"); } } return 0; } /* 10 5 5 3 100 1 1 1 2 5 5 */
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define N 100000 + 10 int n, m, k, q; int vx[N], vy[N]; int sx[N], sy[N]; int main() { int T; scanf("%d", &T); while(T--) { scanf("%d%d%d%d", &n, &m, &k, &q); for(int i = 0; i <= n; i++) { vx[i] = sx[i] = 0; } for(int i = 0; i <= m; i++) { vy[i] = sy[i] = 0; } int x, y; for(int i = 0; i < k; i++) { scanf("%d%d", &x, &y); if(!vx[x]) { vx[x] = 1; } if(!vy[y]) { vy[y] = 1; } } for(int i = 1; i <= n; i++) sx[i] += sx[i - 1] + vx[i]; for(int i = 1; i <= m; i++) sy[i] += sy[i - 1] + vy[i]; int x1, y1, flag; for(int i = 0; i < q; i++) { scanf("%d%d%d%d", &x, &y, &x1, &y1); if((sx[x1] - sx[x - 1] == (x1 - x + 1)) || (sy[y1] - sy[y - 1] == (y1 - y + 1))) printf("Yes\n"); else printf("No\n"); } } return 0; } /* 10 5 5 3 100 1 1 1 2 5 5 */