#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
const int MaxN = 50000 + 5;
int n, m, a, b, c, d, Ans, MaxNum;
int Root[MaxN];
void Add(int x, int s, int t, int l, int r, int Num) {
if (l <= s && r >= t) {
Insert(x, 1, MaxNum, Num);
return;
}
int m = (s + t) >> 1;
if (l <= m) Add(x << 1, s, m, l, r, Num);
if (r >= m + 1) Add(x << 1 | 1, m + 1, t, l, r, Num);
Update(x);
}
int main()
{
scanf("%d%d", &n, &m);
MaxNum = n * 2 + 1;
for (int i = 1; i <= m; ++i) {
scanf("%d%d%d%d", &a, &b, &c, &d);
if (a == 1) {
d = - d + n + 1;
Add(1, 1, n, b, c, d);
}
else {
Ans = GetKth(b, c, d);
printf("%d\n", -Ans + n + 1);
}
}
return 0;
}
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
const int MaxN = 50000 + 5;
int n, m, a, b, c, d, Ans, MaxNum;
int Root[MaxN];
void Add(int x, int s, int t, int l, int r, int Num) {
if (l <= s && r >= t) {
Insert(x, 1, MaxNum, Num);
return;
}
int m = (s + t) >> 1;
if (l <= m) Add(x << 1, s, m, l, r, Num);
if (r >= m + 1) Add(x << 1 | 1, m + 1, t, l, r, Num);
Update(x);
}
int main()
{
scanf("%d%d", &n, &m);
MaxNum = n * 2 + 1;
for (int i = 1; i <= m; ++i) {
scanf("%d%d%d%d", &a, &b, &c, &d);
if (a == 1) {
d = - d + n + 1;
Add(1, 1, n, b, c, d);
}
else {
Ans = GetKth(b, c, d);
printf("%d\n", -Ans + n + 1);
}
}
return 0;
}
原文:http://www.cnblogs.com/JoeFan/p/4170474.html