您的位置:首页 > 其它

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:[分块]

#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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: