1900

EdwardLu

#include <iostream>

using namespace std;

const int N = 1010;
int a[N][N], b[N][N];
int n, m, q;

void insert(int x1,int y1, int x2, int y2, int c)
{
b[x1][y1] += c;
b[x1][y2+1] -= c;
b[x2+1][y1] -= c;
b[x2+1][y2+1] += c;
}

int main()
{
cin >> n >> m >> q;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
cin >> a[i][j];
insert(i, j, i, j, a[i][j]);
}

while(q--)
{
int x1, y1, x2, y2, c;
cin >> x1 >> y1 >> x2 >> y2 >> c;
insert(x1, y1, x2, y2, c);
}

for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
a[i][j] = a[i-1][j] + a[i][j-1] - a[i-1][j-1] + b[i][j];
cout << a[i][j] << ' ';
}
puts("");
}
return 0;
}


#include <iostream>

using namespace std;

const int N = 1010;
int a[N][N], s[N][N];
int n, m, q;

int main()
{
scanf("%d%d%d", &n, &m, &q);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
cin >> a[i][j];
s[i][j] = s[i-1][j] + s[i][j-1] - s[i-1][j-1] + a[i][j];
}

while(q--)
{
int x1,y1,x2,y2;
cin >> x1 >> y1 >> x2 >> y2;
cout << s[x2][y2]-s[x2][y1-1]-s[x1-1][y2]+s[x1-1][y1-1] << endl;
}
return 0;
}


#include <iostream>
using namespace std;

const int N = 100010;
int a[N], b[N];
int n, m;

void insert(int l, int r, int c)
{
b[l] += c;
b[r+1] -= c;
}

int main()
{
cin >> n >> m;
for(int i=1;i<=n;i++)
{
cin >> a[i];
insert(i,i,a[i]);
}

while(m--)
{
int l, r, c;
cin >> l >> r >> c;
insert(l, r, c);
}

for(int i=1;i<=n;i++)
{
a[i] = a[i-1] + b[i];
cout << a[i] << ' ';
}
return 0;
}


#include <iostream>

using namespace std;

const int N = 100010;
int n, m;
int a[N], s[N];

int main()
{
scanf("%d%d", &n, &m);
for(int i=1;i<=n;i++)   scanf("%d", &a[i]);

for(int i=1;i<=n;i++)   s[i] = s[i-1] + a[i];

while(m--)
{
int l, r;
scanf("%d%d", &l, &r);
printf("%d\n", s[r] - s[l-1]);
}
return 0;
}


#include <iostream>
using namespace std;

const int N = 50010;
int n, k, cnt;
int p[N], d[N];  // d[]:到根节点距离

int find(int x)
{
if(p[x] != x)
{
int t = find(p[x]);
d[x]+=d[p[x]];
p[x] = t;
}
return p[x];
}

int main()
{
cin >> n >> k;
for(int i=1;i<=n;i++)  p[i] = i;

int res=0;
while(k--)
{
int m, x, y;
cin >> m >> x >> y;

if(x>n || y>n) res++;
else
{
int px = find(x), py = find(y);
if(m==1)
{
if(px==py && (d[x]-d[y]) % 3)  res++;
else if(px!=py)
{
p[px] = py;
d[px] = d[y] - d[x];
}
}
else
{
if(px==py && (d[x]-d[y]-1)%3)  res++;
else if(px!=py)
{
p[px] = py;
d[px] = d[y]+1-d[x];
}
}
}
}
cout << res << endl;
return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

//  A / b = C...r : C是商，r是余数
vector<int> div(vector<int> &A, int b, int &r)
{
vector<int> C;
r = 0;

for(int i=A.size()-1; i>=0; i--)
{
r = r * 10 + A[i];
C.push_back(r / b);
r = r % b;
}
reverse(C.begin(), C.end());  //  把C倒过来

while(C.size() > 1 && C.back() == 0)  C.pop_back();

return C;
}

int main()
{
string a;
int b, r;
cin >> a >> b;

vector<int> A;
for(int i=a.size()-1; i>=0; i--)  A.push_back(a[i] - '0');

auto C = div(A, b, r);
for(int i=C.size()-1; i>=0; i--) printf("%d", C[i]);
cout << endl << r;

return 0;
}


#include <iostream>
#include <vector>

using namespace std;

//  C = A * b:  A是高精度整数，b是低精度的整数
vector<int> mul(vector<int> &A, int b)
{
vector<int> C;
int t=0;     //  t是进位

for(int i=0; i<A.size() || t; i++)
{
if(i < A.size())  t += A[i] * b;
C.push_back(t % 10);
t /= 10;
}
while(C.size() > 1 && C.back() == 0) C.pop_back();  // 去掉前导0

return C;
}

int main()
{
string a;
int b;
cin >> a >> b;

vector<int> A;
for(int i=a.size()-1; i>=0; i--)  A.push_back(a[i] - '0');

auto C = mul(A, b);

for(int i=C.size()-1; i>=0; i--)  printf("%d", C[i]);
return 0;
}


#include <iostream>
#include <vector>

using namespace std;

// 判断是否有 A >= B
bool cmp(vector<int> &A, vector<int> &B)
{
if (A.size() != B.size()) return A.size() > B.size();

for (int i = A.size() - 1; i >= 0; i -- )
if (A[i] != B[i])
return A[i] > B[i];

return true;
}

//  C = A - B
vector<int> sub(vector<int> &A, vector<int> &B)
{
vector<int> C;
for (int i = 0, t = 0; i < A.size(); i ++ )
{
t = A[i] - t;
if (i < B.size()) t -= B[i];
C.push_back((t + 10) % 10);
if (t < 0) t = 1;
else t = 0;
}

while (C.size() > 1 && C.back() == 0) C.pop_back();   // 去掉前导0
return C;
}

int main()
{
string a, b;
vector<int> A, B;
cin >> a >> b;

for(int i=a.size()-1; i>=0; i--)  A.push_back(a[i] - '0');
for(int i=b.size()-1; i>=0; i--)  B.push_back(b[i] - '0');

vector<int> C;
if(cmp(A, B))  C = sub(A, B);
else C = sub(B, A), cout << "-";

for(int i= C.size()-1; i>=0; i--)  cout << C[i];
cout << endl;

return 0;
}


#include <iostream>
#include <vector>

using namespace std;

vector<int> add(vector<int> &A, vector<int> &B)  // 加取地址符号&为了提高效率，不用把整个数组拷贝一遍
{
vector<int> C;
int t = 0;

for(int i=0; i<A.size() || i<B.size(); i++)
{
if(i<A.size())  t+=A[i];
if(i<B.size())  t+=B[i];
C.push_back(t % 10);
t /= 10;
}
if(t) C.push_back(1);
return C;

}

int main()
{
string a, b;
vector<int> A, B;
cin >> a >> b;     // a = "1234"

for(int i=a.size()-1; i>=0; i--) A.push_back(a[i] - '0');    // A = [4, 3, 2, 1]
for(int i=b.size()-1; i>=0; i--) B.push_back(b[i] - '0');    // 减0是将string类型变成int类型