整体二分板题,没啥好讲的…注意是个环…还有所有贡献会爆longlong,那么只要在加之前判断一下有没有达到需要的值就行了…

CODE

#include <set>
#include <queue>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
char cb[1<<15],*cs=cb,*ct=cb;
#define getc() (cs==ct&&(ct=(cs=cb)+fread(cb,1,1<<15,stdin),cs==ct)?0:*cs++)
template<class T>inline void read(T &res) {
char ch; int flg = 1; for(;!isdigit(ch=getchar());)if(ch=='-')flg=-flg;
for(res=ch-'0';isdigit(ch=getchar());res=res*10+ch-'0'); res*=flg;
}
const int MAXN = 300005;
vector<int>vec[MAXN];
int n, m, k, O[MAXN], L[MAXN], R[MAXN], A[MAXN], ans[MAXN];
struct query { int p, id; }q[MAXN], tmp[MAXN];
LL T[MAXN], val[MAXN];
inline void upd(int x, int val) {
while(x <= m) T[x] += val, x += x&-x;
}
inline LL qsum(int x) { LL re = 0;
while(x) re += T[x], x -= x&-x;
return re;
}
inline void calc(int ql, int qr, int l, int r) {
for(int i = ql; i <= qr; ++i) val[i] = 0;
for(int i = l; i <= r; ++i) {
upd(L[i], A[i]), upd(R[i]+1, -A[i]);
if(L[i] > R[i]) upd(1, A[i]);
}
for(int i = ql; i <= qr; ++i)
for(int j = 0, siz = vec[q[i].id].size(); j < siz; ++j) {
val[i] += qsum(vec[q[i].id][j]);
if(val[i] >= q[i].p) break;
}
for(int i = l; i <= r; ++i) {
upd(L[i], -A[i]), upd(R[i]+1, A[i]);
if(L[i] > R[i]) upd(1, -A[i]);
}
} void solve(int ql, int qr, int vl, int vr) {
if(qr < ql) return;
if(vl == vr) { for(int i = ql; i <= qr; ++i) ans[q[i].id] = vl; return; }
int vmid = (vl + vr) >> 1;
calc(ql, qr, vl, vmid);
int st = ql, ed = qr;
for(int i = ql; i <= qr; ++i)
if(q[i].p <= val[i]) tmp[st++] = q[i];
else q[i].p -= val[i], tmp[ed--] = q[i];
for(int i = ql; i <= qr; ++i) q[i] = tmp[i];
solve(ql, st-1, vl, vmid);
solve(ed+1, qr, vmid+1, vr);
} int main () {
read(n), read(m);
for(int i = 1, x; i <= m; ++i) read(x), vec[x].push_back(i);
for(int i = 1; i <= n; ++i) read(q[i].p), q[i].id = i;
read(k);
for(int i = 1; i <= k; ++i)
read(L[i]), read(R[i]), read(A[i]);
solve(1, n, 1, k+1);
for(int i = 1; i <= n; ++i)
if(ans[i] <= k) printf("%d\n", ans[i]);
else puts("NIE");
}

最新文章

  1. 调试SQLSERVER (二)使用Windbg调试SQLSERVER的环境设置
  2. .Net Task&lt;T&gt;的一种比较神奇的卡死情况(Wait/Result卡死, await能得到结果)
  3. 安装了linux系统的设备上不了网怎么办
  4. 转载-python学习笔记之输入输出功能读取和写入数据
  5. android获取手机录
  6. uboot在s3c2440上的移植(1)
  7. Android实现双进程守护 (转)
  8. 2011年-CUshell编程大赛
  9. 如何将数据库中已有表导入到powerDesigner生成pdm文件
  10. myeclipes使用过程中的错误解决方案
  11. Connect them
  12. POJ 3047 Fibonacci
  13. 【转】Linux Shell脚本面试25问
  14. 赢在面试之Java泛型篇(十二)
  15. (网页)parseFloat在工作中遇到的错误
  16. 关于FastJSON
  17. Ubuntu 下解压tar.xz方法
  18. Oracle 基本语法、触发器、视图
  19. day42
  20. MediaType是application/x-www-form-urlencoded的接口测试方法

热门文章

  1. storm group 的介绍与使用
  2. DecodingGenome(CodeForces-222E)【矩阵快速幂】
  3. re(模块正则表达式)
  4. python pyyaml 使用教程(代码案例)
  5. k8s-搭建 EFK 日志系统
  6. 指针生成网络(Pointer-Generator-Network)原理与实战
  7. 排序之快排(JS)
  8. 《精通Windows API-函数、接口、编程实例》——第4章文件系统
  9. 如何演讲-摘录自TED
  10. 出现 HTTP 错误 500.19 错误代码 0x800700b7