全线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;
}

参考博客

Luogu1527 [国家集训队]矩阵乘法 (整体二分)(Unfinished)的更多相关文章

  1. 洛谷P1527 [国家集训队] 矩阵乘法 [整体二分,二维树状数组]

    题目传送门 矩阵乘法 题目描述 给你一个N*N的矩阵,不用算矩阵乘法,但是每次询问一个子矩形的第K小数. 输入输出格式 输入格式: 第一行两个数N,Q,表示矩阵大小和询问组数: 接下来N行N列一共N* ...

  2. 洛谷$P1527$ [国家集训队]矩阵乘法 整体二分

    正解:整体二分 解题报告: 传送门$QwQ$ 阿看到这种查询若干次第$k$小显然就想到整体二分$QwQ$? 然后现在就只要考虑怎么快速求出一个矩形内所有小于某个数的数的个数? 开始我的想法是离散化然后 ...

  3. P1527 [国家集训队]矩阵乘法 [整体二分]

    权值排序,整体二分,没了. // by Isaunoya #include <bits/stdc++.h> using namespace std; #define rep(i, x, y ...

  4. Luogu-1527 [国家集训队]矩阵乘法

    Luogu-1527 [国家集训队]矩阵乘法 题面 Luogu-1527 题解 昨天学CDQ分治时做了一些题,但是因为题(wo)太(tai)水(lan)了(le)并没有整理 学了一晚上的整体二分,拿这 ...

  5. [Luogu1527][国家集训队]矩阵乘法

    luogu 题意 给你一个\(N*N\)的矩阵,每次询问一个子矩形的第K小数.(居然连修改都不带的) \(N\le500,Q\le60000\) sol 整体二分+二维树状数组裸题. 复杂度是\(O( ...

  6. 【LG1527】[国家集训队]矩阵乘法

    [LG1527][国家集训队]矩阵乘法 题面 洛谷 题解 我也不知道为什么取个这样的名字... 其实就是区间\(kth\)扩展到二维 还是用整体二分搞啦,把树状数组换成二维的 其他的基本没有什么差别 ...

  7. 洛谷 P1527 [国家集训队]矩阵乘法 解题报告

    P1527 [国家集训队]矩阵乘法 题目描述 给你一个\(N*N\)的矩阵,不用算矩阵乘法,但是每次询问一个子矩形的第\(K\)小数. 输入输出格式 输入格式: 第一行两个数\(N,Q\),表示矩阵大 ...

  8. [洛谷P1527] [国家集训队]矩阵乘法

    洛谷题目链接:[国家集训队]矩阵乘法 题目背景 原 <补丁VS错误>请前往P2761 题目描述 给你一个N*N的矩阵,不用算矩阵乘法,但是每次询问一个子矩形的第K小数. 输入输出格式 输入 ...

  9. P1527 [国家集训队]矩阵乘法(整体二分)

    Link 整体二分的经典例题. 对于整体二分,我个人的理解是二分答案套分治. 具体来说就是对答案进行二分,然后对于询问进行类似于权值线段树求区间第 \(k\) 大的分治做法. 首先,我们暴力做法就是对 ...

随机推荐

  1. 树形dp基础

    今天来给大家讲一下数形dp基础 树形dp常与树上问题(lca.直径.重心)结合起来 而这里只讲最最基础的树上dp 1.选课 题目描述 在大学里每个学生,为了达到一定的学分,必须从很多课程里选择一些课程 ...

  2. 2021.05.29【NOIP提高B组】模拟 总结

    T1 题意:给你一个图,可以不花代价经过 \(K\) 条边,问从起点到终点的最短路 考试的想法:设 \(dis_{i,j}\) 表示从起点免费了 \(j\) 条边到 \(i\) 的最短路 然后直接跑 ...

  3. 【动态规划】统计蚂蚁 (ants)

    题目 描述 蚂蚁山上有T(1<=T<=1,000)种蚂蚁,标记为1..T,每种蚂蚁有N_i只蚂蚁(1<=N_i<=100),现有A(A<=5000)只蚂蚁,从中选出S,S ...

  4. 【Redis】quicklist

    Redis List 在Redis3.2版之前,Redis使用压缩列表和双向链表作为List的底层实现.当元素个数比较少并且元素长度比较小时,Redis使用压缩列表实现,否则Redis使用双向链表实现 ...

  5. 解决Invalid bound statement (not found)的异常

    今天在搭建框架的时候,报了一个Invalid bound statement (not found)的异常 经过分析,得出原因: 我的mybatis相关的dao和mapper.xml是通过逆向工程生成 ...

  6. 如何在vscode 背景配置一个动态小女孩

    D:\Microsoft VS Code\resources\app\out\vs\code\electron-browser\workbench <!-- Copyright (C) Micr ...

  7. SAP OLE download to excel

    REPORT RSDEMO01 NO STANDARD PAGE HEADING. * this report demonstrates how to send some ABAP data to a ...

  8. SQL语句的整理

    mysql语句的整理 1.SQL DML 和 DDL 可以把 SQL 分为两个部分:数据操作语言 (DML) 和 数据定义语言 (DDL). SQL (结构化查询语言)是用于执行查询的语法.但是 SQ ...

  9. Python爬取某短视频热点

    写在前面的一些话: 随着短视频的大火,不仅可以给人们带来娱乐,还有热点新闻时事以及各种知识,刷短视频也逐渐成为了日常生活的一部分.本文以一个简单的小例子,简述如何通过Pyhton依托Selenium来 ...

  10. key可重复的Map

    在正常的map操作中,key是不能重复的,如果希望key的内容可以重复,可以用IdentityHashMap 举个栗子 输出结果: public static void main(String[] a ...