题意:给定一个 n*n 的矩阵,然后有 m 个询问,问你每一行或者每一列总是多少,并把这一行清空。

析:这个题不仔细想想,还真不好想,我们可以根据这个题意,知道每一行或者每一列都可以求和公式来求,然后再送去变成0的数,由于每一行或者每一列,

都是等差数列,所以我们只要记录每一个的第一个元素就好,再记录有多少个,然后就可以推算出来。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const LL LNF = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
char s[5];
bool row[maxn], col[maxn]; int main(){
freopen("adjustment.in", "r", stdin);
freopen("adjustment.out", "w", stdout);
while(scanf("%d %d", &n, &m) == 2){
memset(row, false, sizeof row);
memset(col, false, sizeof col);
int x = 0;
LL r = 0, c = 0;
int cntr = 0, cntc = 0;
LL ans = 0;
for(int i = 0; i < m; ++i){
scanf("%s %d", s, &x);
if(s[0] == 'R'){
if(row[x]) ans = 0;
else{
r += x;
++cntr;
ans = (LL)n*(LL)(x+x+n+1)/2LL - (LL)cntc*x - c;
}
row[x] = true;
}
else {
if(col[x]) ans = 0;
else{
c += x;
++cntc;
ans = (LL)n*(LL)(x+x+n+1)/2LL - (LL)cntr*x - r;
}
col[x] = true;
}
printf("%I64d\n", ans);
}
}
return 0;
}

最新文章

  1. Spring 事务
  2. torch-ios框架XCODE使用备忘
  3. 控件(按钮类): ButtonBase, Button, HyperlinkButton, RepeatButton, ToggleButton, AppBarButton, AppBarToggleButton
  4. C#设计模式——生成器模式(Builder Pattern)
  5. 菜鸟-手把手教你把Acegi应用到实际项目中(10)-保护业务方法
  6. CSS Sprites图片处理
  7. C# unix时间戳转换
  8. 武汉科技大学ACM :1001: 零起点学算法34——继续求多项式
  9. Maven中pom.xml的scope
  10. 手动安装Nginx
  11. Android中 实现队列方式处理优先级信息
  12. log4j 详细使用教程【转载】
  13. VRS生成的虚拟观测值存在的问题
  14. ECONOMETRICS CHAPTER3
  15. 关于webpack的path和publicPath。
  16. 乘积尾零——第九届蓝桥杯C语言B组(省赛)第三题
  17. UEFI是什么?与BIOS的区别在哪里?UEFI详解!
  18. uva--242(邮资问题 dp)
  19. 24-集成ASP.NETCore Identity采用EF
  20. DB2 SQL方式查看版本

热门文章

  1. OcelotAPI 简单使用—服务发现、流控
  2. mac 权限问题
  3. cerery
  4. The Apache Thrift API client/server architecture
  5. mongodb学习之:数据库命令以及固定集合
  6. iOS 设备获取唯一标识符汇总
  7. Rime输入工具的修改与编译安装
  8. SpringMVC ajax技术无刷新文件上传下载删除示例
  9. js程序开发-3
  10. (转)定制findbugs规则