QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#292433 | #7118. Closing Time | AuroraH456 | 0 | 89ms | 77888kb | C++14 | 4.0kb | 2023-12-28 04:54:14 | 2024-04-28 08:03:49 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define SZ(X) (int)(X.size())
#define MAX 200005
#define VAL 1000006
#define pii pair <int,int>
#define node first
#define wei second
using namespace std;
struct Data{
ll cost;
int score;
Data operator + (const Data & other) const {
return {cost+other.cost, score+other.score};
}
void operator += (const Data & other){
*this = *this + other;
}
};
struct SegmentTree{
Data data[VAL*4];
int len = VAL-1;
Data merge(Data x, Data y){ // change
return x+y;
}
void initialize(int loc, int le, int ri, Data arr[]){
if (le == ri) data[loc] = arr[le];
else {
int mid = (le+ri)/2;
initialize(loc*2, le, mid, arr);
initialize(loc*2+1, mid+1, ri, arr);
data[loc] = merge(data[loc*2], data[loc*2+1]);
}
}
void update(int loc, int ind, int le, int ri, Data arr[]){
if (le == ri) data[loc] = arr[le];
else {
int mid = (le+ri)/2;
if (ind <= mid) update(loc*2, ind, le, mid, arr);
else update(loc*2+1, ind, mid+1, ri, arr);
data[loc] = merge(data[loc*2], data[loc*2+1]);
}
}
int query(ll targ, int loc, int le, int ri){ // binary search query
if (le == ri) return data[loc].score;
int mid = (le+ri)/2;
if (targ <= data[loc*2].cost) return query(targ, loc*2, le, mid);
else return query(targ-data[loc*2+1].cost, loc*2+1, mid+1, ri) + data[loc*2+1].score;
}
};
int caseNum;
int nodeNum, cityA, cityB;
ll lim;
vector <pii> edge[MAX];
ll dist[MAX][2];
int ans;
int a, b, c;
SegmentTree seg;
Data arr[VAL];
vector <pii> opt; // b (cost for reachable from both), a (cost for reachable from one)
void reset(){
for (int i = 0; i < nodeNum; i++){
edge[i].clear();
dist[i][0] = dist[i][1] = 0;
}
for (int i = 0; i < VAL; i++)
arr[i] = {0,0};
opt.clear();
ans = 0;
}
void dfs(int cur, int par, bool which){ // for each node, find distance from the two cities
for (pii nex : edge[cur]){
if (nex.node == par) continue;
dist[nex.node][which] = dist[cur][which] + nex.wei;
dfs(nex.node, cur, which);
}
}
void enumOverlap(){ // check options for overlap
for (int i = 0; i < nodeNum; i++){ // assume each node -> reachable to at most one city
opt.push_back({max(dist[i][0], dist[i][1]), min(dist[i][0], dist[i][1])});
arr[opt.back().second] += {opt.back().second, 1}; // put in a's
}
seg.initialize(1, 1, seg.len, arr);
sort(opt.begin(), opt.end()); // sort by max distance
ans = max(ans, seg.query(lim, 1, 1, seg.len));
//cout << seg.data[1].cost << " " << dist[1][1] << " " << ans << "\n";
Data defa = {0,0}; // default (pick none)
for (pii o : opt){ // each node before o -> reachable to at least one city
defa += {o.second, 1};
if (defa.cost > lim) return;
arr[o.second] += {-o.second, -1};
arr[o.first-o.second] += {o.first-o.second, 1};
ans = max(ans, seg.query(lim-defa.cost, 1, 1, seg.len)+defa.score);
}
}
/*
void solve(){
cin >> nodeNum >> cityA >> cityB >> lim;
reset();
for (int i = 0; i < nodeNum-1; i++){
cin >> a >> b >> c;
edge[a].push_back({b, c});
edge[b].push_back({a, c});
}
dfs(cityA, -1, 0);
dfs(cityB, -1, 1);
enumOverlap();
cout << ans << "\n";
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
return 0;
}
*/
int max_score(int nodeNum, int cityA, int cityB, ll lim, vector <int> U, vector <int> V, vector <int> W){
reset();
for (int i = 0; i < nodeNum-1; i++){
edge[U[i]].push_back({V[i], W[i]});
edge[V[i]].push_back({U[i], W[i]});
}
dfs(cityA, -1, 0);
dfs(cityB, -1, 1);
enumOverlap();
return ans;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 89ms
memory: 77888kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 200000 31011 61157 8517583098 31011 129396 964383 1655 129396 331139 1655 191487 566483 110385 191487 865248 43212 110385 542661 43212 81682 13766 81682 91774 546589 91774 124706 780638 124706 175650 118706 10421 175650 615314 10421 151953 436270 140430 151...
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 0
result:
wrong answer 1st lines differ - on the 1st token, expected: '451', found: '0'
Subtask #2:
score: 0
Wrong Answer
Test #4:
score: 0
Wrong Answer
time: 4ms
memory: 59004kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 50 23 25 382806473 0 1 375710 1 2 898637 2 3 10402 3 4 536577 4 5 385023 5 6 71075 6 7 543368 7 8 301497 8 9 174394 9 10 711312 10 11 923006 11 12 675532 12 13 838667 13 14 565729 14 15 979816 15 16 862618 16 17 576015 17 18 177751 18 19 306989 19 20 881492...
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 0
result:
wrong answer 1st lines differ - on the 1st token, expected: '96', found: '0'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Wrong Answer
Test #36:
score: 0
Wrong Answer
time: 8ms
memory: 61336kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 4 0 1 9 0 2 2 1 2 3 2 3 3
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 0
result:
wrong answer 1st lines differ - on the 1st token, expected: '6', found: '0'
Subtask #6:
score: 0
Skipped
Dependency #2:
0%
Subtask #7:
score: 0
Skipped
Dependency #3:
0%
Subtask #8:
score: 0
Skipped
Dependency #4:
0%
Subtask #9:
score: 0
Skipped
Dependency #1:
0%