全线RE的代码。。。 先搁这吧,下次再说.flag

//#include <iostream>
#include <cstdio>
//#include <cstring>
#include <algorithm>
//#include <cmath>
#define R(a,b,c) for(register int a = (b); a <= (c); ++ a)
#define nR(a,b,c) for(register int a = (b); a >= (c); -- a)
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Swap(a,b) a^=b^=a^=b
#define ll long long //#define ON_DEBUG #ifdef ON_DEBUG #define D_e_Line printf("\n\n----------\n\n")
#define D_e(x) cout << #x << " = " << x << endl
#define Pause() system("pause") #else #define D_e_Line ; #endif struct ios{
template<typename ATP>ios& operator >> (ATP &x){
x = 0; int f = 1; char c;
for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-') f = -1;
while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
x*= f;
return *this;
}
}io;
using namespace std; const int N = 507;
const int M = 60007; int n; struct Matrix{
int x, y, val;
bool operator < (const Matrix &com) const{
return val < com.val;
}
}mp[N*N];
int cnt; struct Questions{
int xx1, yy1, xx2, yy2, K;
}q[M]; int t[N][N];
inline void Updata(int x, int y, int val){
for(register int i = x; i <= n; i += i&-i)
for(register int j = y; j <= n; j += j&-j)
t[i][j] += val;
}
inline int Query(int x, int y){
int s = 0;
for(register int i = x; i; i -= i&-i)
for(register int j = y; j; j -= j&-j)
s += t[i][j];
return s;
}
// I don't know what happend below
//inline void Updata(int x, int y, int val){
// for(; x <= n; x += x&-x)
// for(; y <= n; y += y&-y)
// t[x][y] += val;
//}
//inline int Query(int x, int y){
// int s = 0;
// for(; x; x -= x&-x)
// for(; y; y -= y&-y)
// s += t[x][y];
// return s;
//} inline int Calc(int xx1, int yy1, int xx2, int yy2){
return Query(xx2, yy2)-Query(xx2, yy1-1)-Query(xx1-1, yy2)+Query(xx1-1, yy1-1);
} int id[N],siz[N],ans[N];
int tmp[N], tmp1[N], tmp2[N];
inline void Dictomy(int l, int r, int L, int R){
if(L > R) return;
if(l == r){
R(i,L,R)
ans[id[i]] = mp[l].val;
return;
}
int mid = (l + r) >> 1, cnt1 = 0, cnt2 = 0; R(i,l,mid) Updata(mp[i].x, mp[i].y, 1); R(i,L,R){
int sum = Calc(q[id[i]].xx1, q[id[i]].yy1, q[id[i]].xx2, q[id[i]].yy2);
if(siz[id[i]]+sum >= q[id[i]].K){
tmp1[++cnt1] = id[i];
}
else{
siz[id[i]] += sum;
tmp2[++cnt2] = id[i];
}
} R(i,l,mid) Updata(mp[i].x, mp[i].y, -1); int qCnt = L-1;
R(i,1,cnt1){
tmp[++qCnt] = tmp1[i];
id[qCnt] = tmp[qCnt];
}
R(i,1,cnt2){
tmp[++qCnt] = tmp2[i];
id[qCnt] = tmp[qCnt];
} Dictomy(l, mid, L, L + cnt1 - 1);
Dictomy(mid + 1, r, L + cnt1, R);
} //#define FileInTheHole
int main(){
//#ifdef FileInTheHole
// D_e_Line;
// freopen("in.txt", "r", stdin);
//#endif
int Que;
io >> n >> Que; R(i,1,n){
R(j,1,n){
int x;
io >> x;
mp[++cnt] = (Matrix){i, j, x};
}
} sort(mp + 1, mp + cnt + 1); R(i,1,Que){
io >> q[i].xx1 >> q[i].yy1 >> q[i].xx2 >> q[i].yy2 >> q[i].K;
id[i] = i;
} Dictomy(1, cnt, 1, Que); R(i,1,Que)
printf("%d\n", ans[i]); return 0;
}

参考博客

最新文章

  1. Nodejs 饭店
  2. CDN缓存那些事
  3. iOS - (调用系统本机发送短信功能)
  4. Qt之QThread(深入理解)
  5. D - Charm Bracelet 背包问题
  6. Struts2 本是非单例的,与Spring集成就默认为单例
  7. Codeforces Round #205 (Div. 2) : D
  8. Codeforces Round #261 (Div. 2)——Pashmak and Buses
  9. dfs序和欧拉序
  10. Ubuntu16.04 编译 OpenJDK7
  11. Android+appium +python 点击坐标tap方法的封装
  12. linux 挂载共享文件夹
  13. vgcreate语法
  14. ASP.NET -- WebForm -- .aspx与.aspx.cs文件
  15. Spring cache 使用说明
  16. 我的devops实践经验分享一二
  17. 微信小程序笔记&lt;一&gt;初识小程序
  18. 设计模式——适配器模式(type-c转3.5mm耳机口)
  19. switch语句的执行过程
  20. Java -- 获取MAC地址

热门文章

  1. vue项目经常遇到的Error: Loading chunk * failed
  2. JavaScript Object学习笔记二
  3. JavaScript写放大镜效果
  4. jQuery做轮播图
  5. skywalking链路监控
  6. Vue的基础语法
  7. C#中List实体类转换为object 并把参数返回到前端
  8. browserify的standalone的含义
  9. 匿名对象作为方法的参数和返回值与Random概念和基本使用
  10. JavaWEB04-Maven&amp;Mybatis