Submission #2232353
Source Code Expand
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <iterator>
#include <functional>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <list>
#include <sstream>
#include <cstring>
#include <stdio.h>
#include <complex>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
typedef long double LD;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LD, LD> PDD;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<char> VCH;
typedef vector<LD> VLD;
typedef vector<string> VS;
typedef vector<VS> VSS;
typedef vector<VI> VVI;
typedef vector<VLL> VVLL;
typedef vector<VCH> VVCH;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<PDD> VPDD;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#define next fake_next
#define prev fake_prev
#define left fake_left
#define right fake_right
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i, 0, t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
const LD PI = acos(-1.0);
const LD EPS = 1e-6;
const LL INF = 1e9;
const LL LINF = 1e18;
const LL mod = 1000000007;
const LL MAX = 2000 + 7;
int n;
int m;
int f[MAX][MAX];
int s[MAX][MAX];
int hor[MAX][MAX];
int ver[MAX][MAX];
int sum_hor[MAX][MAX];
int sum_ver[MAX][MAX];
int main()
{
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
//freopen("In.txt", "r", stdin);
int q;
cin >> n >> m >> q;
char ch;
FOR(i, 0, n)
FOR(j, 0, m)
{
cin >> ch;
f[i][j] = ch - '0';
}
FOR(i, 0, n)
FOR(j, 0, m - 1)
if (f[i][j] && f[i][j + 1])
hor[i][j] = 1;
FOR(i, 0, n - 1)
FOR(j, 0, m)
if (f[i][j] && f[i + 1][j])
ver[i][j] = 1;
s[0][0] = f[0][0];
FOR(i, 1, n)
s[i][0] = f[i][0] + s[i - 1][0];
FOR(i, 1, m)
s[0][i] = f[0][i] + s[0][i - 1];
FOR(i, 1, n)
FOR(j, 1, m)
s[i][j] = f[i][j] + s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];
sum_hor[0][0] = hor[0][0];
sum_ver[0][0] = ver[0][0];
FOR(i, 1, n)
sum_hor[i][0] = hor[i][0] + sum_hor[i - 1][0];
FOR(i, 1, m - 1)
sum_hor[0][i] = hor[0][i] + sum_hor[0][i - 1];
FOR(i, 1, n)
FOR(j, 1, m - 1)
sum_hor[i][j] = hor[i][j] + sum_hor[i - 1][j] + sum_hor[i][j - 1] - sum_hor[i - 1][j - 1];
FOR(i, 1, n - 1)
sum_ver[i][0] = ver[i][0] + sum_ver[i - 1][0];
FOR(i, 1, m)
sum_ver[0][i] = ver[0][i] + sum_ver[0][i - 1];
FOR(i, 1, n - 1)
FOR(j, 1, m)
sum_ver[i][j] = ver[i][j] + sum_ver[i - 1][j] + sum_ver[i][j - 1] - sum_ver[i - 1][j - 1];
int x1, y1, x2, y2;
REP(Q, q)
{
cin >> x1 >> y1 >> x2 >> y2;
--x1, --x2;
--y1, --y2;
int blue = s[x2][y2];
if (x1)
blue -= s[x1 - 1][y2];
if (y1)
blue -= s[x2][y1 - 1];
if (x1 && y1)
blue += s[x1 - 1][y1 - 1];
int edges_hor = 0, edges_ver = 0;
if (y1 < y2)
{
--y2;
edges_hor = sum_hor[x2][y2];
if (x1)
edges_hor -= sum_hor[x1 - 1][y2];
if (y1)
edges_hor -= sum_hor[x2][y1 - 1];
if (x1 && y1)
edges_hor += sum_hor[x1 - 1][y1 - 1];
++y2;
}
if (x1 < x2)
{
--x2;
edges_ver = sum_ver[x2][y2];
if (x1)
edges_ver -= sum_ver[x1 - 1][y2];
if (y1)
edges_ver -= sum_ver[x2][y1 - 1];
if (x1 && y1)
edges_ver += sum_ver[x1 - 1][y1 - 1];
++x2;
}
cout << blue - edges_hor - edges_ver << endl;
}
cin >> n;
return 0;
}
Submission Info
Submission Time |
|
Task |
C - Nuske vs Phantom Thnook |
User |
vjudge5 |
Language |
C++14 (GCC 5.4.1) |
Score |
700 |
Code Size |
3635 Byte |
Status |
AC |
Exec Time |
518 ms |
Memory |
96000 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
700 / 700 |
Status |
|
|
Set Name |
Test Cases |
Sample |
s1.txt, s2.txt |
All |
01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, s1.txt, s2.txt |
Case Name |
Status |
Exec Time |
Memory |
01.txt |
AC |
488 ms |
95744 KB |
02.txt |
AC |
505 ms |
95744 KB |
03.txt |
AC |
476 ms |
95744 KB |
04.txt |
AC |
504 ms |
95616 KB |
05.txt |
AC |
481 ms |
96000 KB |
06.txt |
AC |
518 ms |
95616 KB |
07.txt |
AC |
457 ms |
81280 KB |
08.txt |
AC |
474 ms |
95488 KB |
09.txt |
AC |
471 ms |
95616 KB |
10.txt |
AC |
497 ms |
95616 KB |
11.txt |
AC |
479 ms |
95744 KB |
12.txt |
AC |
436 ms |
62592 KB |
13.txt |
AC |
386 ms |
94336 KB |
14.txt |
AC |
373 ms |
11264 KB |
15.txt |
AC |
348 ms |
6784 KB |
16.txt |
AC |
373 ms |
11136 KB |
17.txt |
AC |
378 ms |
94336 KB |
18.txt |
AC |
374 ms |
81664 KB |
19.txt |
AC |
373 ms |
9216 KB |
20.txt |
AC |
468 ms |
64128 KB |
21.txt |
AC |
443 ms |
66560 KB |
22.txt |
AC |
509 ms |
95616 KB |
23.txt |
AC |
384 ms |
20352 KB |
24.txt |
AC |
508 ms |
95616 KB |
25.txt |
AC |
357 ms |
10880 KB |
26.txt |
AC |
371 ms |
15616 KB |
27.txt |
AC |
368 ms |
9088 KB |
28.txt |
AC |
384 ms |
81664 KB |
29.txt |
AC |
385 ms |
94336 KB |
30.txt |
AC |
366 ms |
11136 KB |
31.txt |
AC |
442 ms |
67456 KB |
32.txt |
AC |
475 ms |
67200 KB |
33.txt |
AC |
450 ms |
95616 KB |
34.txt |
AC |
481 ms |
67200 KB |
35.txt |
AC |
454 ms |
81024 KB |
36.txt |
AC |
474 ms |
83072 KB |
37.txt |
AC |
470 ms |
95360 KB |
38.txt |
AC |
482 ms |
83072 KB |
39.txt |
AC |
444 ms |
67328 KB |
40.txt |
AC |
467 ms |
67200 KB |
41.txt |
AC |
447 ms |
95616 KB |
42.txt |
AC |
470 ms |
95360 KB |
43.txt |
AC |
451 ms |
94976 KB |
44.txt |
AC |
467 ms |
84992 KB |
45.txt |
AC |
2 ms |
6400 KB |
46.txt |
AC |
2 ms |
6400 KB |
47.txt |
AC |
3 ms |
8448 KB |
48.txt |
AC |
3 ms |
10496 KB |
s1.txt |
AC |
3 ms |
10496 KB |
s2.txt |
AC |
3 ms |
10496 KB |