Codeforces Round #307 (Div. 2)
2015-06-13 00:26
246 查看
官方题解
A. GukiZ and Contest
照着题意写...
tags:[模拟]
B. ZgukistringZ
枚举做几个B,几个C,维护最大的Num_of_B+Num_of_C的数量
tags:[枚举] [字符串]
C. GukiZ hates Boxes
tags:[]
D. GukiZ and Binary Operations
tags:[]
E. GukiZ and GukiZiana
题目大意:给出n个数字,q个操作,每个操作有1,2两种:
1: 1 L R X ,A[L]...A[R]间的所有元素增加X
2: 2 Y ,求A数组中值为Y,且相距最远的两个Y的距离是多少
数据范围:(1 ≤ n ≤ 5 * 105, 1 ≤ q ≤ 5 * 104 ,1 ≤ ai ≤ 109 ,1 ≤ l ≤ r ≤ n, 0 ≤ x ≤ 109 ,1 ≤ y ≤ 109)
tags:[分块]
View Code
A. GukiZ and Contest
照着题意写...
tags:[模拟]
B. ZgukistringZ
枚举做几个B,几个C,维护最大的Num_of_B+Num_of_C的数量
tags:[枚举] [字符串]
C. GukiZ hates Boxes
tags:[]
D. GukiZ and Binary Operations
tags:[]
E. GukiZ and GukiZiana
题目大意:给出n个数字,q个操作,每个操作有1,2两种:
1: 1 L R X ,A[L]...A[R]间的所有元素增加X
2: 2 Y ,求A数组中值为Y,且相距最远的两个Y的距离是多少
数据范围:(1 ≤ n ≤ 5 * 105, 1 ≤ q ≤ 5 * 104 ,1 ≤ ai ≤ 109 ,1 ≤ l ≤ r ≤ n, 0 ≤ x ≤ 109 ,1 ≤ y ≤ 109)
tags:[分块]
#include <cstdio> #include <vector> #include <algorithm> using namespace std; const int BS = 1000; const int INF = 0x3f3f3f3f; vector <pair<int, int> > G[BS]; int f[BS]; int lower(int x, const vector<pair<int, int> >&G) { int l = 0, r = G.size()-1, m; if (x < G[l].first || x > G[r].first) { return 0; } while (l < r) { m = (l+r) >> 1; if (x <= G[m].first) { r = m; } else { l = m+1; } } if (G[l].first == x) return G[l].second; return 0; } int upper(int x, const vector<pair<int, int> >&G) { int l = 0, r = G.size()-1, m; if (x < G[l].first || x > G[r].first) { return 0; } while (l < r) { m = (l+r+1)>>1; if (x >= G[m].first) { l = m; } else { r = m-1; } } if (G[r].first == x) return G[r].second; return 0; } int main() { int n, m, ord, l, r, x; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d", &x); G[i/BS].push_back(make_pair(x, i)); } for (int i = 0; i < BS; i++) { sort(G[i].begin(), G[i].end()); } for (int i = 0; i < m; i++) { scanf("%d", &ord); if (ord == 1) { scanf("%d%d%d", &l, &r, &x); int L = l/BS; int R = r/BS; if (L < R) { for (int i = L+1; i <= R-1; i++) { f[i] = min(f[i]+x, INF); } for (int i = 0; i < (int)G[L].size(); i++) { if (l <= G[L][i].second && G[L][i].second <= r) { G[L][i].first = min(G[L][i].first+x, INF); } } sort(G[L].begin(), G[L].end()); } for (int i = 0; i < (int)G[R].size(); i++) { if (l <= G[R][i].second && G[R][i].second <= r) { G[R][i].first = min(G[R][i].first+x, INF); } } sort(G[R].begin(), G[R].end()); } else { scanf("%d", &x); int L = n+1, R = 0; for (int i = 0; i <= n/BS; i++) { int idx = lower(x-f[i], G[i]); if (!idx) continue; L = idx; break; } if (L == n+1) { printf("-1\n"); continue; } for (int i = n/BS; i >= 0; i--) { int idx = upper(x-f[i], G[i]); if (!idx) continue; R = idx; break; } printf("%d\n", R-L); } } return 0; }
View Code
相关文章推荐
- linux下安装jdk1.7
- JNI学习笔记
- 运算符
- Android事件传递机制
- 关于innodb purge thread和master thread
- ConfuserEx
- [LeetCode][JavaScript]Implement Stack using Queues
- linux安装jdk
- ubuntu10 系统root用户无法正常使用tab键补全命令
- tomcat进行redeploy时出错:could not be completely deleted
- 毕业论文从0到完成获得东西
- Uva - 10763 - Foreign Exchange
- Uva - 10763 - Foreign Exchange
- Android 真机连接本地PC服务器
- 【剑指offer】面试题五:从尾到头打印链表
- Candy
- 本机能ping通虚拟机,但无法通过SSH登录到虚拟机上的linux系统
- 记一次服务器上架的总结和反思
- Open SLL ciper suits
- Linked List Cycle II || LeetCode