Thu, 07 Feb 2019 14:29:33 GMT

master
大蒟蒻 7 years ago
parent 61febfe45c
commit 5f59690215

@ -8,39 +8,43 @@
对于每一天维护这一天之前结束的相同时长的所有旅程中cost最小的不然暴力会TLE。
### C - Sockets
### C - The Union of k-Segments
前缀和瞎搞搞就可以了。
### D - Sockets
将电脑连同id一起扔进multimap里然后对socket排序从最小的开始这是个什么神奇道理检查是否有符合的电脑如果没有就`(x+1)/2`直到找到这样的电脑或比当前最小电脑所用量还小其实直接循环个31次应该也能过
### D - Bipartite Graph
### E - Bipartite Graph
首先已知这是一个二分图,将其染色并统计两部分数量。将孤立的点选择加到集合一还是二,取最大值即可,时间复杂度与输入复杂度相同。
### E - Pearls in a Row
### F - Pearls in a Row
拿set随便一搞就过了注意Codeforces默认是32位编译的。实在拿不定怎么输出就cout吧
### F - Kiki & Little Kiki 1
### G - Kiki & Little Kiki 1
multiset.upper_bound()
### G - 传递
### H - 传递
题意看起来非常奇怪但是实际上只要用bitset存一下一个点连向了哪些点即可。只要保证对于每一条边其终点所连向的点的集合为起点连向的点的集合的子集即可判断这个图是“传递”的。
### H - HDU Today
### I - HDU Today
`map/unordered_map`+单源最短路
### I - Counter Strike
### J - Counter Strike
转换为减掉平均值后求出的前缀和的顺序对数。
### J - 区间交
### K - 区间交
说实话,没怎么看懂题解。望大佬们不吝告知。
### K - Music in Car
### L - Music in Car
[正版题解](http://codeforces.com/blog/entry/49160)
@ -49,3 +53,7 @@ multiset.upper_bound()
> Right end we will move in the following way: if we can add partly song and we have enough time to listen it — we take it (also add this song to*half*) and add to time$(t_r+1)/2$and add to the answer$a_r$. In the other case we have two cases. First — we add current song as full song, second — we add current song as partly song. Here we need to choose case with less with the total time. Also here we need to correctly add song to sets and update total time and the answer. If total time became more than*k*we are not allowed to move*r*. Now we need to update global answer with the current value of answer.
>
> Left end we will move in the following way: if we took song as full song we delete it from*full*, subtract from total time length of this song. In the other case we delete it from*half*and subtract from the total time the$(t_r+1)/2$. After that we try to take some song from*full*. If the size of*full*is 0, we can not do that. If we done it we need to change total time on the songs on the current segment.
### M - Alice and Bob
multiset搞一下又忘记clear了

@ -1,29 +1,30 @@
#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
int main()
{
map<string, map<string, int>> M;
int n, m, x;
cin >> n;
string s1, s2;
while (n--)
{
M.clear();
cin >> m;
while (m--)
{
cin >> s1 >> s2 >> x;
M[s2][s1] += x;
}
for (auto &x : M)
{
cout << x.first << endl;
for (auto &y : x.second)
cout << " |----" << y.first << '(' << y.second << ')' << endl;
}
if (n)
cout << endl;
}
return 0;
map<string, map<string, int>> M;
int n, m, x;
cin >> n;
string s1, s2;
while (n--)
{
M.clear();
cin >> m;
while (m--)
{
cin >> s1 >> s2 >> x;
M[s2][s1] += x;
}
for (auto &x : M)
{
cout << x.first << endl;
for (auto &y : x.second)
cout << " |----" << y.first << '(' << y.second << ')' << endl;
}
if (n)
cout << endl;
}
return 0;
}

@ -1,3 +1,4 @@
#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
@ -6,37 +7,37 @@ tuple<int, int, int, int> a[N << 1];
unsigned long long best[N];
int main()
{
memset(best, 0x3f, sizeof(best));
int n, x;
scanf("%d%d", &n, &x);
for (int i = 0, x, y, z; i < n; i++)
{
scanf("%d%d%d", &x, &y, &z);
a[i << 1] = {x, -1, y, z};
a[i << 1 | 1] = {y, 1, x, z};
}
n <<= 1;
sort(a, a + n);
auto ans = numeric_limits<unsigned long long>::max();
for (int i = 0; i < n; i++)
{
int l, r, t, c;
tie(l, t, r, c) = a[i];
if (t == -1)
{
int time = r - l + 1;
if (time <= x)
ans = min(ans, c + best[x - time]);
}
if (t == 1)
{
int time = l - r + 1;
best[time] = min(best[time], (unsigned long long)c);
}
//printf("** %d %d %d %d %lld\n", l, r, t, c, ans);
}
if (ans >= 2e9 + 2)
ans = -1ll;
printf("%lld", ans);
return 0;
memset(best, 0x3f, sizeof(best));
int n, x;
scanf("%d%d", &n, &x);
for (int i = 0, x, y, z; i < n; i++)
{
scanf("%d%d%d", &x, &y, &z);
a[i << 1] = { x, -1, y, z };
a[i << 1 | 1] = { y, 1, x, z };
}
n <<= 1;
sort(a, a + n);
auto ans = numeric_limits<unsigned long long>::max();
for (int i = 0; i < n; i++)
{
int l, r, t, c;
tie(l, t, r, c) = a[i];
if (t == -1)
{
int time = r - l + 1;
if (time <= x)
ans = min(ans, c + best[x - time]);
}
if (t == 1)
{
int time = l - r + 1;
best[time] = min(best[time], (unsigned long long)c);
}
//printf("** %d %d %d %d %lld\n", l, r, t, c, ans);
}
if (ans >= 2e9 + 2)
ans = -1ll;
printf("%lld", ans);
return 0;
}

@ -1,46 +1,34 @@
#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 50;
#define f first
#define s second
multimap<int, int> comps;
pair<int, int> sock[N];
//#define nxt(x) (((~(decltype(x))0) << 1 & x) << 1)
//#define nxt(x) ((x | 1) << 1)
#define nxt(x) ((x + 1) >> 1)
int a[N], b[N], c, u;
const int N = 2e6 + 10;
pair<int, int> a[N];
int c[N];
int main()
{
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1, x; i <= n; i++)
scanf("%d", &x), comps.insert(make_pair(x, i));
for (int i = 1; i <= m; i++)
scanf("%d", &sock[i].f), sock[i].s = i;
sort(sock + 1, sock + m + 1);
for (int i = 1; i <= m && comps.size(); i++)
ios::sync_with_stdio(false);
int n, k;
cin >> n >> k;
for (int i = 0, l, r; i < n; i++)
{
int x = sock[i].f;
int y = comps.begin()->first;
for (int cnt = 0; x >= y; x = nxt(x), cnt++)
{
auto ite = comps.find(x);
if (ite != comps.end())
{
a[sock[i].s] = cnt;
b[ite->second] = sock[i].s;
c++, u += cnt;
comps.erase(ite);
break;
}
}
cin >> l >> r;
a[i << 1] = make_pair(l, -1);
a[i << 1 | 1] = make_pair(r, 1);
}
printf("%d %d\n", c, u);
for (int i = 1; i <= m; i++)
printf("%d ", a[i]);
putchar('\n');
for (int i = 1; i <= n; i++)
printf("%d ", b[i]);
n <<= 1;
sort(a, a + n);
for (int i = 1; i <= n; i++) c[i] = -a[i - 1].second;
for (int i = 1; i <= n; i++) c[i] += c[i - 1];
for (int i = 0; i <= n; i++) c[i] -= k;
vector<pair<int, int>> ans;
for (int i = 1, st = -1; i <= n; i++)
{
if (c[i - 1] < 0 && c[i] >= 0) st = i;
if (c[i] < 0 && c[i - 1] >= 0) ans.push_back(make_pair(st - 1, i - 1));
}
cout << ans.size() << endl;
for (const auto &x : ans)
cout << a[x.first].first << ' ' << a[x.second].first << endl;
return 0;
}

@ -1,26 +1,30 @@
cmake_minimum_required(VERSION 3.10)
set(CMAKE_CXX_STANDARD 17)
add_compile_options("/Zc:__cplusplus")
include_directories("D:\\PortableApps\\MSYS2\\mingw64\\include\\c++\\8.2.1\\x86_64-w64-mingw32")
add_executable("A" "A.cpp")
add_executable("B" "B.cpp")
add_executable("C" "C.cpp")
add_executable("D" "D.cpp")
add_executable("E" "E.cpp")
add_executable("F" "F.cpp")
add_executable("G" "G.cpp")
add_executable("H" "H.cpp")
add_executable("I" "I.cpp")
add_executable("J" "J.cpp")
add_executable("K" "K.cpp")
add_executable("L" "L.cpp")
add_executable("M" "M.cpp")
add_executable("N" "N.cpp")
add_executable("O" "O.cpp")
add_executable("P" "P.cpp")
add_executable("Q" "Q.cpp")
add_executable("R" "R.cpp")
add_executable("S" "S.cpp")
add_executable("T" "T.cpp")
add_executable("U" "U.cpp")
add_executable("V" "V.cpp")
cmake_minimum_required(VERSION 3.0)
set(CMAKE_CXX_STANDARD 17)
if(MSVC)
add_compile_options("/Zc:__cplusplus")
endif()
include_directories("C:\\Programs\\GCC\\x86_64-8.1.0-release-posix-seh-rt_v6-rev0\\lib\\gcc\\x86_64-w64-mingw32\\8.1.0\\include\\c++\\x86_64-w64-mingw32")
add_executable(A A.cpp)
add_executable(B B.cpp)
add_executable(C C.cpp)
add_executable(D D.cpp)
add_executable(E E.cpp)
add_executable(F F.cpp)
add_executable(G G.cpp)
add_executable(H H.cpp)
add_executable(I I.cpp)
add_executable(J J.cpp)
add_executable(K K.cpp)
add_executable(L L.cpp)
add_executable(M M.cpp)
add_executable(N N.cpp)
add_executable(O O.cpp)
add_executable(P P.cpp)
add_executable(Q Q.cpp)
add_executable(R R.cpp)
add_executable(S S.cpp)
add_executable(T T.cpp)
add_executable(U U.cpp)
add_executable(V V.cpp)
add_executable(W W.cpp)

@ -1,46 +1,47 @@
#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
const int N = 10010, M = 100010;
int adj[N], nxt[M << 1], to[M << 1], ecnt, col[N];
inline void addEdge(int f, int t)
{
ecnt++;
nxt[ecnt] = adj[f];
adj[f] = ecnt;
to[ecnt] = t;
}
void dfs(int x)
{
for (int e = adj[x], t; e; e = nxt[e])
if (t = to[e], !col[to[e]])
{
col[t] = 3 - col[x];
dfs(t);
}
}
const int N = 2e5 + 50;
#define f first
#define s second
multimap<int, int> comps;
pair<int, int> sock[N];
//#define nxt(x) (((~(decltype(x))0) << 1 & x) << 1)
//#define nxt(x) ((x | 1) << 1)
#define nxt(x) ((x + 1) >> 1)
int a[N], b[N], c, u;
int main()
{
int T;
scanf("%d", &T);
while (T--)
{
memset(adj, 0, sizeof(adj)), ecnt = 0;
memset(col, 0, sizeof(col));
int n, m, u, v;
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++)
scanf("%d%d", &u, &v), addEdge(u, v), addEdge(v, u);
if (m == 0) u = 1;
col[u] = 1;
dfs(u);
int cnt[] = {0, 0, 0};
for (int i = 1; i <= n; i++)
cnt[col[i]]++;
int ans = 0;
for (int i = 0; i <= cnt[0]; i++)
ans = max(ans, (cnt[1] + i) * (cnt[2] + cnt[0] - i));
printf("%d\n", ans - m);
}
return 0;
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1, x; i <= n; i++)
scanf("%d", &x), comps.insert(make_pair(x, i));
for (int i = 1; i <= m; i++)
scanf("%d", &sock[i].f), sock[i].s = i;
sort(sock + 1, sock + m + 1);
for (int i = 1; i <= m && comps.size(); i++)
{
int x = sock[i].f;
int y = comps.begin()->first;
for (int cnt = 0; x >= y; x = nxt(x), cnt++)
{
auto ite = comps.find(x);
if (ite != comps.end())
{
a[sock[i].s] = cnt;
b[ite->second] = sock[i].s;
c++, u += cnt;
comps.erase(ite);
break;
}
}
}
printf("%d %d\n", c, u);
for (int i = 1; i <= m; i++)
printf("%d ", a[i]);
putchar('\n');
for (int i = 1; i <= n; i++)
printf("%d ", b[i]);
return 0;
}

@ -1,32 +1,47 @@
#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 50;
int a[N];
const int N = 10010, M = 100010;
int adj[N], nxt[M << 1], to[M << 1], ecnt, col[N];
inline void addEdge(int f, int t)
{
ecnt++;
nxt[ecnt] = adj[f];
adj[f] = ecnt;
to[ecnt] = t;
}
void dfs(int x)
{
for (int e = adj[x], t; e; e = nxt[e])
if (t = to[e], !col[to[e]])
{
col[t] = 3 - col[x];
dfs(t);
}
}
int main()
{
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", a + i);
vector<pair<int, int>> ans;
set<int> s;
int last = 0;
for (int i = 1; i <= n; i++)
if (s.empty())
s.insert(a[last = i]);
else if (s.count(a[i]))
ans.push_back(make_pair(last, i)), s.clear();
else
s.insert(a[i]);
if (ans.empty())
puts("-1");
else
int T;
scanf("%d", &T);
while (T--)
{
ans.rbegin()->second = n;
printf("%d\n", ans.size());
for (auto &x : ans)
printf("%d %d\n", x.first, x.second);
memset(adj, 0, sizeof(adj)), ecnt = 0;
memset(col, 0, sizeof(col));
int n, m, u, v;
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++)
scanf("%d%d", &u, &v), addEdge(u, v), addEdge(v, u);
if (m == 0) u = 1;
col[u] = 1;
dfs(u);
int cnt[] = {0, 0, 0};
for (int i = 1; i <= n; i++)
cnt[col[i]]++;
int ans = 0;
for (int i = 0; i <= cnt[0]; i++)
ans = max(ans, (cnt[1] + i) * (cnt[2] + cnt[0] - i));
printf("%d\n", ans - m);
}
return 0;
}

@ -1,22 +1,33 @@
#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 50;
int a[N];
int main()
{
multiset<int> s;
int n, x;
char buf[20];
for (; ~scanf("%d", &n); putchar('\n'), s.clear())
for (int i = 0; i < n; i++)
if (scanf("%s%d", buf, &x), buf[1] == 'u')
s.insert(x);
else
{
auto ite = s.upper_bound(x);
if (ite != s.begin())
printf("%d\n", *--ite), s.erase(ite);
else
puts("No Element!");
}
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", a + i);
vector<pair<int, int>> ans;
set<int> s;
int last = 0;
for (int i = 1; i <= n; i++)
if (s.empty())
s.insert(a[last = i]);
else if (s.count(a[i]))
ans.push_back(make_pair(last, i)), s.clear();
else
s.insert(a[i]);
if (ans.empty())
puts("-1");
else
{
ans.rbegin()->second = n;
printf("%d\n", ans.size());
for (auto &x : ans)
printf("%d %d\n", x.first, x.second);
}
return 0;
}

@ -1,33 +1,23 @@
#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 11;
bitset<N> a[2][N];
char buf[N];
int main()
{
int T, n;
scanf("%d", &T);
while (T--)
{
memset(a, 0, sizeof(a));
scanf("%d", &n);
multiset<int> s;
int n, x;
char buf[20];
for (; ~scanf("%d", &n); putchar('\n'), s.clear())
for (int i = 0; i < n; i++)
{
scanf("%s", buf);
for (int j = 0; j < n; j++)
if (scanf("%s%d", buf, &x), buf[1] == 'u')
s.insert(x);
else
{
if (buf[j] == 'P') a[0][i].set(j);
if (buf[j] == 'Q') a[1][i].set(j);
auto ite = s.upper_bound(x);
if (ite != s.begin())
printf("%d\n", *--ite), s.erase(ite);
else
puts("No Element!");
}
}
bool flag = true;
for (int k = 0; k < 2 && flag; k++)
for (int i = 0; i < n && flag; i++)
for (int j = 0; j < n && flag; j++)
if (a[k][i][j] && (a[k][i] | a[k][j]) != a[k][i])
flag = false;
puts(flag ? "T" : "N");
}
return 0;
}

@ -2,66 +2,33 @@
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
unordered_map<string, int> m;
int getId(const char *str)
{
auto ite = m.find(str);
if (ite != m.end())
return ite->second;
else
return m[str] = m.size();
}
const int N = 20050;
int adj[N], nxt[N], to[N], len[N], dis[N], ecnt;
inline void addEdge(int f, int t, int l)
{
ecnt++;
nxt[ecnt] = adj[f];
adj[f] = ecnt;
to[ecnt] = t;
len[ecnt] = l;
}
inline void rst()
{
m.clear();
ecnt = 0;
memset(adj, 0, sizeof(adj));
memset(dis, 0x3f3f3f3f, sizeof(dis));
}
char buf1[50], buf2[50];
struct node
{
int u, w;
};
bool operator<(const node x, const node y) noexcept { return x.w > y.w; }
priority_queue<node> h;
const int N = 1 << 11;
bitset<N> a[2][N];
char buf[N];
int main()
{
int n;
while (scanf("%d", &n), ~n)
int T, n;
scanf("%d", &T);
while (T--)
{
rst();
scanf("%s%s", buf1, buf2);
int S = getId(buf1), T = getId(buf2);
for (int i = 0, x, y, z; i < n; i++)
{
scanf("%s%s%d", buf1, buf2, &z);
x = getId(buf1), y = getId(buf2);
addEdge(x, y, z), addEdge(y, x, z);
}
dis[S] = 0;
h.push({S, dis[S]});
while (!h.empty())
memset(a, 0, sizeof(a));
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
auto u = h.top().u, w = h.top().w;
h.pop();
if (w != dis[u]) continue;
for (int e = adj[u]; e; e = nxt[e])
if (dis[to[e]] > w + len[e])
dis[to[e]] = w + len[e], h.push({to[e], dis[to[e]]});
scanf("%s", buf);
for (int j = 0; j < n; j++)
{
if (buf[j] == 'P') a[0][i].set(j);
if (buf[j] == 'Q') a[1][i].set(j);
}
}
if (dis[T] > 15000) dis[T] = -1;
printf("%d\n", dis[T]);
bool flag = true;
for (int k = 0; k < 2 && flag; k++)
for (int i = 0; i < n && flag; i++)
for (int j = 0; j < n && flag; j++)
if (a[k][i][j] && (a[k][i] | a[k][j]) != a[k][i])
flag = false;
puts(flag ? "T" : "N");
}
return 0;
}
}

@ -2,41 +2,66 @@
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int a[N];
int c[N];
#define lowbit(x) ((x) & -(x))
int get(int x)
unordered_map<string, int> m;
int getId(const char *str)
{
int ans = 0;
for (; x; x -= lowbit(x)) ans += c[x];
return ans;
auto ite = m.find(str);
if (ite != m.end())
return ite->second;
else
return m[str] = m.size();
}
void inc(int x)
const int N = 20050;
int adj[N], nxt[N], to[N], len[N], dis[N], ecnt;
inline void addEdge(int f, int t, int l)
{
for (; x < N; x += lowbit(x)) c[x]++;
ecnt++;
nxt[ecnt] = adj[f];
adj[f] = ecnt;
to[ecnt] = t;
len[ecnt] = l;
}
inline void rst()
{
m.clear();
ecnt = 0;
memset(adj, 0, sizeof(adj));
memset(dis, 0x3f3f3f3f, sizeof(dis));
}
char buf1[50], buf2[50];
struct node
{
int u, w;
};
bool operator<(const node x, const node y) noexcept { return x.w > y.w; }
priority_queue<node> h;
int main()
{
multiset<int> s;
int T, n, avg;
scanf("%d", &T);
while (T--)
int n;
while (scanf("%d", &n), ~n)
{
memset(c, 0, sizeof(c));
long long ans = 0;
s.clear();
scanf("%d%d", &n, &avg);
for (int i = 1; i <= n; i++) scanf("%d", a + i), a[i] = a[i] - avg + a[i - 1];
vector<pair<int, int>> v(n);
for (int i = 1; i <= n; i++) v[i - 1] = {a[i], -i};
sort(begin(v), end(v));
for (auto &x : v)
rst();
scanf("%s%s", buf1, buf2);
int S = getId(buf1), T = getId(buf2);
for (int i = 0, x, y, z; i < n; i++)
{
scanf("%s%s%d", buf1, buf2, &z);
x = getId(buf1), y = getId(buf2);
addEdge(x, y, z), addEdge(y, x, z);
}
dis[S] = 0;
h.push({S, dis[S]});
while (!h.empty())
{
ans += get(-x.second) + (x.first > 0);
inc(-x.second);
auto u = h.top().u, w = h.top().w;
h.pop();
if (w != dis[u]) continue;
for (int e = adj[u]; e; e = nxt[e])
if (dis[to[e]] > w + len[e])
dis[to[e]] = w + len[e], h.push({to[e], dis[to[e]]});
}
printf("%lld\n", ans);
if (dis[T] > 15000) dis[T] = -1;
printf("%d\n", dis[T]);
}
return 0;
}

@ -3,26 +3,38 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
long long a[N];
pair<int, int> p[N];
int a[N];
int c[N];
#define lowbit(x) ((x) & -(x))
int get(int x)
{
int ans = 0;
for (; x; x -= lowbit(x)) ans += c[x];
return ans;
}
void inc(int x)
{
for (; x < N; x += lowbit(x)) c[x]++;
}
int main()
{
int n, k, m;
while (~scanf("%d%d%d", &n, &k, &m))
multiset<int> s;
int T, n, avg;
scanf("%d", &T);
while (T--)
{
for (int i = 1; i <= n; i++)
scanf("%lld", a + i), a[i] += a[i - 1];
for (int i = 0; i < m; i++)
scanf("%d%d", &p[i].first, &p[i].second);
sort(p, p + m);
priority_queue<int> h;
memset(c, 0, sizeof(c));
long long ans = 0;
for (int i = 0; i < m; i++)
s.clear();
scanf("%d%d", &n, &avg);
for (int i = 1; i <= n; i++) scanf("%d", a + i), a[i] = a[i] - avg + a[i - 1];
vector<pair<int, int>> v(n);
for (int i = 1; i <= n; i++) v[i - 1] = {a[i], -i};
sort(begin(v), end(v));
for (auto &x : v)
{
h.push(-p[i].second);
if (h.size() < k) continue;
if (h.size() > k) h.pop();
ans = max(ans, a[-h.top()] - a[p[i].first - 1]);
ans += get(-x.second) + (x.first > 0);
inc(-x.second);
}
printf("%lld\n", ans);
}

@ -2,47 +2,29 @@
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 50;
int a[N], t[N];
#define hlf(x) (((x) + 1) >> 1)
const int N = 100010;
long long a[N];
pair<int, int> p[N];
int main()
{
int n, w, k;
scanf("%d%d%d", &n, &w, &k);
for (int i = 0; i < n; i++) scanf("%d", a + i);
for (int i = 0; i < n; i++) scanf("%d", t + i);
multiset<int> s1, s2;
int tsum = 0, hsum = 0, ans = 0;
for (int l = 0, r = 0; r < n; r++)
int n, k, m;
while (~scanf("%d%d%d", &n, &k, &m))
{
s1.insert(t[r]);
tsum += hlf(t[r]);
hsum += a[r];
if (s1.size() > w)
for (int i = 1; i <= n; i++)
scanf("%lld", a + i), a[i] += a[i - 1];
for (int i = 0; i < m; i++)
scanf("%d%d", &p[i].first, &p[i].second);
sort(p, p + m);
priority_queue<int> h;
long long ans = 0;
for (int i = 0; i < m; i++)
{
int x = *s1.begin();
s2.insert(x);
tsum += x - hlf(x);
s1.erase(s1.begin());
h.push(-p[i].second);
if (h.size() < k) continue;
if (h.size() > k) h.pop();
ans = max(ans, a[-h.top()] - a[p[i].first - 1]);
}
for (; l <= r && tsum > k; hsum -= a[l++])
if (t[l] < *s1.begin())
s2.erase(s2.find(t[l])), tsum -= t[l];
else
{
s1.erase(s1.find(t[l]));
tsum -= hlf(t[l]);
if (!s2.empty())
{
auto x = s2.end();
--x;
tsum += hlf(*x) - *x;
s1.insert(*x);
s2.erase(x);
}
}
ans = max(ans, hsum);
printf("%lld\n", ans);
}
printf("%d", ans);
return 0;
}

@ -2,7 +2,47 @@
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 50;
int a[N], t[N];
#define hlf(x) (((x) + 1) >> 1)
int main()
{
int n, w, k;
scanf("%d%d%d", &n, &w, &k);
for (int i = 0; i < n; i++) scanf("%d", a + i);
for (int i = 0; i < n; i++) scanf("%d", t + i);
multiset<int> s1, s2;
int tsum = 0, hsum = 0, ans = 0;
for (int l = 0, r = 0; r < n; r++)
{
s1.insert(t[r]);
tsum += hlf(t[r]);
hsum += a[r];
if (s1.size() > w)
{
int x = *s1.begin();
s2.insert(x);
tsum += x - hlf(x);
s1.erase(s1.begin());
}
for (; l <= r && tsum > k; hsum -= a[l++])
if (t[l] < *s1.begin())
s2.erase(s2.find(t[l])), tsum -= t[l];
else
{
s1.erase(s1.find(t[l]));
tsum -= hlf(t[l]);
if (!s2.empty())
{
auto x = s2.end();
--x;
tsum += hlf(*x) - *x;
s1.insert(*x);
s2.erase(x);
}
}
ans = max(ans, hsum);
}
printf("%d", ans);
return 0;
}

@ -2,7 +2,31 @@
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
pair<int, int> a[N], b[N];
int main()
{
multiset<int> s;
int T, n;
scanf("%d", &T);
while (T--)
{
s.clear();
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d%d", &a[i].first, &a[i].second);
for (int i = 0; i < n; i++)
scanf("%d%d", &b[i].first, &b[i].second);
sort(a, a + n), sort(b, b + n);
int cnt = 0;
for (int i = 0, j = 0; i < n; i++)
{
while (j < n && a[i].first >= b[j].first)
s.insert(b[j++].second);
auto ite = s.upper_bound(a[i].second);
if (ite != s.begin()) s.erase(--ite), cnt++;
}
printf("%d\n", cnt);
}
return 0;
}

@ -0,0 +1,8 @@
#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
int main()
{
return 0;
}
Loading…
Cancel
Save