QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#494158 | #9141. Array Spread | ucup-team008# | WA | 18ms | 3620kb | C++17 | 4.4kb | 2024-07-27 14:26:59 | 2024-07-27 14:26:59 |
Judging History
你现在查看的是最新测评结果
- [2024-09-18 18:58:44]
- hack成功,自动添加数据
- (/hack/840)
- [2024-09-18 18:53:02]
- hack成功,自动添加数据
- (/hack/839)
- [2024-07-29 03:53:23]
- hack成功,自动添加数据
- (/hack/753)
- [2024-07-29 03:51:16]
- hack成功,自动添加数据
- (/hack/752)
- [2024-07-29 03:50:24]
- hack成功,自动添加数据
- (/hack/751)
- [2024-07-29 03:48:52]
- hack成功,自动添加数据
- (/hack/750)
- [2024-07-27 14:26:59]
- 提交
answer
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <complex>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>
using namespace std;
// BEGIN NO SAD
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
typedef vector<int> vi;
#define f first
#define s second
#define derr if(0) cerr
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << flush;
// END NO SAD
template<class Fun>
class y_combinator_result {
Fun fun_;
public:
template<class T>
explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}
template<class ...Args>
decltype(auto) operator()(Args &&...args) {
return fun_(std::ref(*this), std::forward<Args>(args)...);
}
};
template<class Fun>
decltype(auto) y_combinator(Fun &&fun) {
return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
}
template<class T>
bool updmin(T& a, T b) {
if(b < a) {
a = b;
return true;
}
return false;
}
template<class T>
bool updmax(T& a, T b) {
if(b > a) {
a = b;
return true;
}
return false;
}
typedef int64_t ll;
void rsolve() {
int n, q;
cin >> n >> q;
vector<int> allv;
vector<array<int, 2>> edges(q);
auto valid = [&](ll thresh) -> bool {
vector<ll> dp(sz(allv));
for(int qq = 0; qq < sz(allv); qq++) {
for(auto [a, b]: edges) {
int aidx = lb(allv.begin(), allv.end(), a) - allv.begin();
int bidx = lb(allv.begin(), allv.end(), b) - allv.begin();
updmax(dp[bidx], dp[aidx] + 2);
updmax(dp[aidx], dp[bidx] - thresh);
}
for(int i = 1; i < sz(dp); i++) updmax(dp[i], dp[i-1]);
}
for(auto [a, b]: edges) {
int aidx = lb(allv.begin(), allv.end(), a) - allv.begin();
int bidx = lb(allv.begin(), allv.end(), b) - allv.begin();
if(updmax(dp[bidx], dp[aidx] + 2)) return false;
if(updmax(dp[aidx], dp[bidx] - thresh)) return false;
for(int i = 1; i < sz(dp); i++) if(updmax(dp[i], dp[i-1])) return false;
}
return true;
};
for(auto& x: edges) {
cin >> x[0] >> x[1];
x[0]--;
assert(x[0] < x[1]);
allv.pb(x[0]);
allv.pb(x[1]);
}
sort(all(allv));
allv.resize(unique(all(allv)) - allv.begin());
ll lhs = 2;
ll rhs = 10000;
while(lhs < rhs) {
int mid = (lhs+rhs)/2;
if(valid(mid)) rhs = mid;
else lhs = mid+1;
}
if(lhs%2 == 0) cout << (lhs/2) << "\n";
else {
cout << (lhs * (998244353+1)/2)%998244353 << "\n";
}
}
void solve() {
int t;
cin >> t;
while(t--) rsolve();
}
// what would chika do
// are there edge cases (N=1?)
// are array sizes proper (scaled by proper constant, for example 2* for koosaga tree)
// integer overflow?
// DS reset properly between test cases
// are you doing geometry in floating points
// are you not using modint when you should
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
input:
3 3 3 1 3 2 3 1 2 12 6 2 3 5 7 1 9 4 8 1 2 7 11 4 5 3 4 2 3 1 2 4 4 1 1
output:
1 2 499122178
result:
ok 3 number(s): "1 2 499122178"
Test #2:
score: 0
Accepted
time: 2ms
memory: 3620kb
input:
2000 1000000000 1 259923446 367011266 1000000000 1 882434225 971573327 1000000000 1 41585677 470369580 1000000000 1 371902212 947250194 1000000000 1 787209148 924205796 1000000000 1 259074809 960876164 1000000000 1 148079314 188254573 1000000000 1 940091047 948318624 1000000000 1 40636497 743979446 ...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok 2000 numbers
Test #3:
score: 0
Accepted
time: 4ms
memory: 3552kb
input:
1000 1000000000 5 575330909 661595447 708422488 913945134 658050911 930246647 786571892 904549453 851755566 969150871 1000000000 2 198072104 844159589 8876188 644559580 1000000000 2 740802634 976972118 783909534 898449184 1000000000 2 871819537 941611957 465883854 640988372 1000000000 1 99458969 462...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 ...
result:
ok 1000 numbers
Test #4:
score: 0
Accepted
time: 3ms
memory: 3596kb
input:
500 1000000000 13 964546318 987364574 367845944 907446075 259314137 890312338 458318546 959971971 353677471 522446336 782931403 845199078 514387878 786979588 532634932 793056892 905393511 960628299 747423889 986373313 796099347 833069525 906969434 971335651 574582540 647534593 1000000000 6 987712893...
output:
3 1 3 1 1 1 1 1 1 3 2 1 1 1 3 1 2 1 1 2 1 3 1 1 1 2 1 2 2 1 1 1 1 1 1 1 3 1 1 1 1 2 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 1 2 2 1 1 3 1 2 1 1 1 1 2 3 1 1 1 1 1 1 1 3 2 1 3 2 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 3 1 1 1 1 1 1 1 2 1 1 2 1 1 1 2 1 4 1 2 1 4 1 3 1 1 1 1 1 2 1 1 4 1 ...
result:
ok 500 numbers
Test #5:
score: 0
Accepted
time: 18ms
memory: 3500kb
input:
250 1000000000 10 844342043 888135880 127033337 726074967 581308029 893912240 414276384 752837267 565680461 863374082 230362895 477723054 210479116 423381051 325072305 427826920 178306222 756423471 376470949 993759748 1000000000 2 468173597 607783582 266359996 863641680 1000000000 7 206599093 941381...
output:
2 1 2 1 3 3 1 1 1 2 1 2 2 1 3 5 2 1 1 1 2 1 2 1 3 1 2 1 3 499122178 1 1 1 1 3 1 1 1 3 3 3 1 4 1 1 1 1 1 1 1 1 5 1 4 2 1 3 1 1 1 2 5 2 1 2 6 2 2 1 2 1 1 1 5 8 2 1 2 1 1 2 2 2 1 1 5 8 3 1 1 1 8 2 6 1 1 4 2 1 1 1 1 2 2 1 2 1 1 1 1 1 1 2 1 2 1 1 4 1 1 3 1 2 3 3 2 5 1 1 1 3 2 1 1 1 3 1 1 2 1 1 1 1 3 1 1 ...
result:
ok 250 numbers
Test #6:
score: -100
Wrong Answer
time: 16ms
memory: 3540kb
input:
250 1000000000 4 10495745 465086423 465086424 609997778 396956207 663037010 253873206 396956206 1000000000 33 596279983 655818820 226461062 338625457 407323582 423049163 711408063 778512581 220274357 226461061 702491412 711408062 686978949 688730316 369564474 434159428 778512582 787885602 675683057 ...
output:
1 2 499122178 5 6 2 1 10 6 1 499122183 1 4 3 1 3 1 499122178 2 499122179 10 499122178 1 499122179 4 1 7 1 3 2 2 2 499122178 2 499122178 499122178 2 499122179 5 3 4 17 1 2 2 3 4 1 3 499122178 499122179 2 3 499122179 2 7 3 499122187 6 2 1 2 499122179 2 2 2 499122178 499122179 499122183 499122178 49912...
result:
wrong answer 3rd numbers differ - expected: '748683266', found: '499122178'