QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#292324 | #7118. Closing Time | Goldenglow1427 | Compile Error | / | / | C++14 | 3.8kb | 2023-12-28 00:13:20 | 2024-04-28 08:01:43 |
Judging History
你现在查看的是最新测评结果
- [2024-04-28 08:01:43]
- 管理员手动重测本题所有提交记录
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2023-12-28 00:13:20]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2023-12-28 00:13:20]
- 提交
answer
/*
ID: Victor Chen [mail_vi1]
PROG: CF436E
LANG: C++
*/
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <cassert>
using namespace std;
typedef long long ll;
const int Maxn = 3e5;
class SegTree
{
public:
int cnt, root;
struct Node
{
int l, r;
int val, ch[2];
ll sum;
}p[Maxn*20];
int build(int l, int r)
{
cnt++;
p[cnt].l = l, p[cnt].r = r;
return cnt;
}
void buildtree(int l, int r)
{
cnt = 0;
root = build(l, r);
}
void modify(int x, int k, int v)
{
if(p[x].l == p[x].r)
{
p[x].val += v;
p[x].sum += p[x].l * v;
return;
}
int mid = (p[x].l+p[x].r)/2;
if(k <= mid)
{
if(!p[x].ch[0]) p[x].ch[0] = build(p[x].l, mid);
modify(p[x].ch[0], k, v);
}
else
{
if(!p[x].ch[1]) p[x].ch[1] = build(mid+1, p[x].r);
modify(p[x].ch[1], k, v);
}
p[x].val = p[p[x].ch[0]].val + p[p[x].ch[1]].val;
p[x].sum = p[p[x].ch[0]].sum + p[p[x].ch[1]].sum;
}
ll find_min_kth(int x, int k)
{
if(p[x].l == p[x].r)
return p[x].l * k;
if(k == 0)
return 0;
if(p[x].ch[0])
{
if(k <= p[p[x].ch[0]].val) return find_min_kth(p[x].ch[0], k);
else return p[p[x].ch[0]].sum + find_min_kth(p[x].ch[1], k-p[p[x].ch[0]].val);
}
else
return find_min_kth(p[x].ch[1], k);
}
}tree;
int n, k;
struct Node
{
int id;
ll cst1, cst2;
void input(int x)
{
id = x;
scanf("%lld%lld", &cst1, &cst2);
}
bool operator < (const Node x) const
{
if(cst2 != x.cst2)
return cst2 < x.cst2;
else
return cst1 < x.cst1;
}
}p[Maxn+10];
ll sum, ans;
struct Pair
{
int id;
ll val;
bool operator < (const Pair x) const
{
return x.val < val;
}
Pair(){}
Pair(int id, ll val)
{
this->id = id;
this->val = val;
}
};
priority_queue<Pair> q;
int val[Maxn+10];
int main()
{
tree.buildtree(1, 1e9);
scanf("%d%d", &n, &k);
for(int i=1; i<=n; i++)
p[i].input(i);
sort(p+1, p+n+1);
int min_2_count = max(0, k-n);
for(int i=1; i<=min_2_count; i++)
{
sum += p[i].cst1;
tree.modify(1, p[i].cst2-p[i].cst1, 1);
}
for(int i=min_2_count+1; i<=n; i++)
tree.modify(1, p[i].cst1, 1);
ans = sum + tree.find_min_kth(1, k-min_2_count);
int pos = min_2_count;
for(int i=min_2_count+1; i<=n && i<k; i++)
{
tree.modify(1, p[i].cst1, -1);
tree.modify(1, p[i].cst2-p[i].cst1, 1);
sum += p[i].cst1;
ll curans = sum + tree.find_min_kth(1, k-i);
if(ans > curans)
{
ans = curans;
pos = i;
}
}
for(int i=1; i<=pos; i++)
{
val[p[i].id] = 1;
q.push(Pair(p[i].id, p[i].cst2-p[i].cst1));
}
for(int i=pos+1; i<=n; i++)
q.push(Pair(p[i].id, p[i].cst1));
for(int i=1; i<=k-pos; i++)
{
val[q.top().id]++;
q.pop();
}
printf("%lld\n", ans);
for(int i=1; i<=n; i++)
printf("%d", val[i]);
printf("\n");
return 0;
}
詳細信息
answer.code: In function ‘int main()’: answer.code:136:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 136 | scanf("%d%d", &n, &k); | ~~~~~^~~~~~~~~~~~~~~~ answer.code: In member function ‘void Node::input(int)’: answer.code:97:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 97 | scanf("%lld%lld", &cst1, &cst2); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/bin/ld: /tmp/ccxwrx9W.o: in function `main': answer.code:(.text.startup+0x0): multiple definition of `main'; /tmp/cc3eQqNZ.o:implementer.cpp:(.text.startup+0x0): first defined here /usr/bin/ld: /tmp/cc3eQqNZ.o: in function `main': implementer.cpp:(.text.startup+0x744): undefined reference to `max_score(int, int, int, long long, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)' collect2: error: ld returned 1 exit status