QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#33587 | #1429. Hit | chenxia25 | WA | 42ms | 14072kb | C++20 | 6.2kb | 2022-06-03 21:06:14 | 2022-06-03 21:06:15 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
bool Mbe;
namespace temp {
// NORMAL
using ll = long long; // using i128 = __int128_t;
using uint = unsigned; using ull = unsigned long long; // using u128 = __uint128_t;
using db = double; using ld = long double; // using f128 = __float128;
#define int ll
// #define db ld
using tii = tuple<int, int>; using ti3 = tuple<int, int, int>; using ti4 = tuple<int, int, int, int>;
#define mt(...) make_tuple(__VA_ARGS__)
#define X(x) get<0>(x)
#define Y(x) get<1>(x)
#define Z(x) get<2>(x)
#define W(x) get<3>(x)
using vi = vector<int>; using vii = vector<tii>; using vi3 = vector<ti3>; using vi4 = vector<ti4>;
using vvi = vector<vi>; using vvii = vector<vii>; using vvi3 = vector<vi3>; using vvi4 = vector<vi4>;
#define pf(...) emplace_front(__VA_ARGS__)
#define pb(...) emplace_back(__VA_ARGS__)
#define REP(i, l, r) for(int i = (l); i <= (r); ++i)
#define PER(i, r, l) for(int i = (r); i >= (l); --i)
#define y0 kehaixing
#define y1 yigeiwoligiaogiao
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
int lowbit(int x) { return x & -x; }
template<class T, class U> void chkmx(T &x, U y) { if(y > x) x = y; }
template<class T, class U> void chkmn(T &x, U y) { if(y < x) x = y; }
// FASTIO
namespace fastio {
// #define fread_io
#ifdef fread_io
char buf[1 << 16], *st, *ed, wbuf[1 << 16], *wst = wbuf, *wed = wbuf + (1 << 16);
char gc() { return st == ed && (ed = (st = buf) + fread(buf, 1, 1 << 16, stdin), st == ed) ? -1 : *st++; }
__attribute__((destructor)) void flush() { fwrite(wbuf, 1, wst - wbuf, stdout), wst = wbuf; }
void pc(char x) { wst == wed && (flush(), 0), *wst++ = x; }
#else
char gc() { return getchar(); } void pc(char x) { putchar(x); }
#endif
#define notspace(x) (!isspace(x) && ~(x))
template<class T = int> T read() {
T x = 0; char c = gc(); bool ne = false;
while(!isdigit(c)) ne |= c == '-', c = gc();
while(isdigit(c)) x = 10 * x + (c ^ 48), c = gc();
return ne ? -x : x;
}
int reads(char *s) {
int n = 0; char c = gc();
while(!notspace(c)) c = gc();
while(notspace(c)) s[n++] = c, c = gc();
return s[n] = 0, n;
}
template<class T> void prt(T x) {
x < 0 && (pc('-'), x = -x);
x > 9 && (prt(x / 10), 0);
pc(x % 10 ^ 48);
}
void prts(const char *s, int n = INT_MAX) { while(n-- && *s) pc(*s++); }
} using fastio::gc; using fastio::pc;
using fastio::read; using fastio::reads; using fastio::prt; using fastio::prts;
// MATH
constexpr int P = 0;
constexpr ll lnf = 0x3f3f3f3f3f3f3f3f;
#ifdef int
constexpr int inf = 0x3f3f3f3f3f3f3f3f;
#else
constexpr int inf = 0x3f3f3f3f;
#endif
int gcd(int x, int y) { return __gcd(x, y); }
int exgcd(int a, int b, int &x, int &y) {
if(!b) return x = 1, y = 0, a;
int d = exgcd(b, a % b, y, x);
return y -= a / b * x, d;
}
int qpow(int x, int y = P - 2, int p = P) {
int res = 1;
while(y) {
if(y & 1) res = (ll)res * x % p;
x = (ll)x * x % p;
y >>= 1;
} return res;
}
int inv(int a, int p = P) {
int x, y, d = exgcd(a, p, x, y);
if(d != 1) return -1;
return x < 0 ? x + p : x;
}
namespace modint {
void addto(int &x, int y) { x += y, x >= P && (x -= P), x < 0 && (x += P); }
int add(int x, int y) { return x < 0 && (x += P), x += y, x >= P ? x - P : x < 0 ? x + P : x; }
int add0(int x) { return x < 0 ? x + P : x; }
}
// using namespace modint;
template<int N, int p = P> struct fc_t {
int iv[N], fc[N], ifc[N];
fc_t() {
iv[1] = 1; REP(i, 2, N - 1) iv[i] = (ll)iv[p % i] * (p - p / i) % p;
fc[0] = ifc[0] = 1; REP(i, 1, N - 1) fc[i] = (ll)fc[i - 1] * i % p, ifc[i] = (ll)ifc[i - 1] * iv[i] % p;
}
int operator()(int n, int m) {
if(m < 0 || m > n) return 0;
return (ll)fc[n] * ifc[m] % p * ifc[n - m] % p;
}
};
#define fc_init(...) fc_t<__VA_ARGS__> comb; int *iv = comb.iv, *fc = comb.fc, *ifc = comb.ifc
template<int N, int p = P> struct comb_t {
int comb[N][N];
comb_t() {
comb[0][0] = 1;
REP(i, 1, N - 1) REP(j, 0, i) comb[i][j] = ((j ? comb[i - 1][j - 1] : 0) + comb[i - 1][j]) % p;
}
};
#define comb_init(...) comb_t<__VA_ARGS__> _comb; auto comb = _comb.comb
} using namespace temp;
constexpr int N = 2e5 + 10;
int n, m;
int l[N], r[N];
vi nums;
void disc() {
nums.clear();
REP(i, 1, n) nums.pb(l[i]), nums.pb(r[i]);
sort(ALL(nums)), nums.resize(unique(ALL(nums)) - nums.begin());
m = SZ(nums);
REP(i, 1, n) {
l[i] = lower_bound(ALL(nums), l[i]) - nums.begin() + 1;
r[i] = lower_bound(ALL(nums), r[i]) - nums.begin() + 1;
}
}
vii nei[N];
int dis[N];
int C[N];
bool spfa() {
REP(i, 0, m) C[i] = 0;
REP(i, 0, m) dis[i] = inf;
dis[0] = 0;
queue<int> q;
static bool inq[N];
REP(i, 0, m) inq[i] = false;
q.push(0), inq[0] = true;
while(SZ(q)) {
int x = q.front();
q.pop(), inq[x] = false;
for(tii e : nei[x]) {
int y, len; tie(y, len) = e;
if(dis[x] + len < dis[y]) {
dis[y] = dis[x] + len;
C[y] = C[x] + 1;
if(C[y] >= m + 1) return false;
if(!inq[y]) q.push(y), inq[y] = true;
}
}
}
return true;
}
vi chs;
bool chk(int L) {
chs.clear();
REP(i, 0, m) nei[i].clear();
nei[0].pb(m, n);
REP(i, 1, m) nei[i - 1].pb(i, 1), nei[i].pb(i - 1, 0);
REP(i, 1, n) {
nei[l[i] - 1].pb(r[i], L);
nei[r[i]].pb(l[i] - 1, -1);
}
if(!spfa()) return false;
REP(i, 1, m) if(dis[i] > dis[i - 1]) chs.pb(i);
// cout << "L = " << L << "\n";
// REP(i, 0, m) cout << dis[i] << " "; puts("which is dis");
return true;
}
void mian() {
n = read();
REP(i, 1, n) l[i] = read(), r[i] = read();
disc();
int ans = n;
if(chk(1)) { ans = 1; goto edlp; }
PER(i, 20, 0) if(ans > 1 << i && chk(ans - (1 << i))) {
ans -= 1 << i;
}
chk(ans);
edlp:;
prt(ans), pc(' '), prt(SZ(chs)), pc(' ');
for(int x : chs) prt(nums[x - 1]), pc(" \n"[x == chs.back()]);
}
bool Med;
signed main() {
fprintf(stderr, "(%.3lfMB used (not including static!!!))\n", (&Mbe - &Med) / 1048576.);
// freopen("xxx.in", "r", stdin); freopen("xxx.out", "w", stdout);
int t = 1;
t = read();
while(t--) mian();
fprintf(stderr, "(%.3lfs used)\n", (db)clock() / CLOCKS_PER_SEC);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 11924kb
input:
4 4 0 1 2 3 4 5 3 5 5 0 70 0 10 20 30 40 50 60 70 8 -1 7 -2 -1 -9 -7 -8 9 -9 -7 -2 4 -7 4 3 9 5 0 1 0 2 2 3 3 5 4 5
output:
1 3 0 2 4 4 4 0 20 40 60 2 3 -9 -2 3 2 4 0 1 3 4
result:
ok ok, tt = 4
Test #2:
score: 0
Accepted
time: 2ms
memory: 13984kb
input:
1 1 0 1
output:
1 1 0
result:
ok ok, tt = 1
Test #3:
score: 0
Accepted
time: 4ms
memory: 13980kb
input:
3 1 -1000000000 1000000000 1 -1000000000 -999999999 1 999999999 1000000000
output:
1 1 -1000000000 1 1 -1000000000 1 1 999999999
result:
ok ok, tt = 3
Test #4:
score: 0
Accepted
time: 40ms
memory: 14072kb
input:
100000 1 -755794993 -744839313 1 638832683 645984490 1 333736843 342792055 1 -412526164 -400411740 1 193156287 205856204 1 266085745 268256106 1 789502967 806620391 1 85305828 86560242 1 -655573585 -644094805 1 517734490 518776542 1 -966001098 -958188900 1 -780504491 -762439365 1 -896592598 -8804653...
output:
1 1 -755794993 1 1 638832683 1 1 333736843 1 1 -412526164 1 1 193156287 1 1 266085745 1 1 789502967 1 1 85305828 1 1 -655573585 1 1 517734490 1 1 -966001098 1 1 -780504491 1 1 -896592598 1 1 -557316732 1 1 664292314 1 1 -629158110 1 1 -202815742 1 1 -640869188 1 1 -229963066 1 1 -785668909 1 1 48944...
result:
ok ok, tt = 100000
Test #5:
score: 0
Accepted
time: 30ms
memory: 13860kb
input:
100000 1 -392749917 -319069731 1 761382535 804248178 1 -858764838 -819815600 1 -87503649 -20800126 1 -69252318 64456029 1 -848092983 -666742404 1 -659061625 -620054847 1 -982031817 -883932130 1 -47104919 97672798 1 -494834028 -456770262 1 496748206 692802903 1 572757539 669651153 1 -484466016 -41314...
output:
1 1 -392749917 1 1 761382535 1 1 -858764838 1 1 -87503649 1 1 -69252318 1 1 -848092983 1 1 -659061625 1 1 -982031817 1 1 -47104919 1 1 -494834028 1 1 496748206 1 1 572757539 1 1 -484466016 1 1 729473771 1 1 -428804236 1 1 212864606 1 1 -381428604 1 1 813986190 1 1 -573957931 1 1 -125982928 1 1 -7723...
result:
ok ok, tt = 100000
Test #6:
score: 0
Accepted
time: 28ms
memory: 13872kb
input:
100000 1 -422738609 -95619025 1 496655203 761501973 1 -253341552 895113150 1 -213934938 560617332 1 257193179 510136024 1 -684784337 -650911183 1 -999254900 62633326 1 -627557633 641989470 1 -682383675 66116491 1 -859630523 340664034 1 -422590930 433070710 1 259879968 316877801 1 -90014752 991378355...
output:
1 1 -422738609 1 1 496655203 1 1 -253341552 1 1 -213934938 1 1 257193179 1 1 -684784337 1 1 -999254900 1 1 -627557633 1 1 -682383675 1 1 -859630523 1 1 -422590930 1 1 259879968 1 1 -90014752 1 1 -789762673 1 1 -750992244 1 1 -964513526 1 1 -723869577 1 1 44144467 1 1 -550241786 1 1 386352264 1 1 757...
result:
ok ok, tt = 100000
Test #7:
score: 0
Accepted
time: 41ms
memory: 11976kb
input:
100000 1 -146170891 -135832850 1 -758721094 -739814745 1 434418655 436843128 1 584625787 597671579 1 -54920782 -48746711 1 -890924962 -874340357 1 -955254050 -945006677 1 276114326 279390556 1 -291805472 -288200984 1 673823575 685514644 1 -43237398 -31640268 1 -239622315 -224829882 1 -596965402 -595...
output:
1 1 -146170891 1 1 -758721094 1 1 434418655 1 1 584625787 1 1 -54920782 1 1 -890924962 1 1 -955254050 1 1 276114326 1 1 -291805472 1 1 673823575 1 1 -43237398 1 1 -239622315 1 1 -596965402 1 1 -902355499 1 1 262300444 1 1 -172688572 1 1 289036433 1 1 106949065 1 1 -733199280 1 1 -146867424 1 1 95061...
result:
ok ok, tt = 100000
Test #8:
score: 0
Accepted
time: 42ms
memory: 12008kb
input:
100000 1 -938525664 -817076126 1 -932701889 -823854498 1 -198817321 -90954343 1 852989237 895167117 1 -657597128 -592296022 1 -189337058 -60845257 1 -308394755 -143079067 1 -798793040 -658589397 1 587269730 632505978 1 463959892 651681553 1 210139744 354710208 1 -738322653 -579254528 1 -473167271 -4...
output:
1 1 -938525664 1 1 -932701889 1 1 -198817321 1 1 852989237 1 1 -657597128 1 1 -189337058 1 1 -308394755 1 1 -798793040 1 1 587269730 1 1 463959892 1 1 210139744 1 1 -738322653 1 1 -473167271 1 1 -719122089 1 1 -135498368 1 1 798473093 1 1 772169233 1 1 732432771 1 1 -164220287 1 1 605378245 1 1 4418...
result:
ok ok, tt = 100000
Test #9:
score: 0
Accepted
time: 22ms
memory: 13968kb
input:
100000 1 -124550996 175843021 1 -993480749 369513273 1 -472345946 866834459 1 51146719 619481540 1 -953985291 -388861986 1 30060232 86153621 1 397966610 670657620 1 228037899 527397835 1 -328812046 777147616 1 528770087 999819348 1 -443642177 430027557 1 -985366041 937429463 1 286165886 375753871 1 ...
output:
1 1 -124550996 1 1 -993480749 1 1 -472345946 1 1 51146719 1 1 -953985291 1 1 30060232 1 1 397966610 1 1 228037899 1 1 -328812046 1 1 528770087 1 1 -443642177 1 1 -985366041 1 1 286165886 1 1 -553313072 1 1 -22755036 1 1 -586567462 1 1 384242088 1 1 59282828 1 1 -787530941 1 1 97548261 1 1 -858346451...
result:
ok ok, tt = 100000
Test #10:
score: 0
Accepted
time: 27ms
memory: 11928kb
input:
18139 4 -336270587 -330557331 -252002330 -239258910 -186846904 -186440987 848243159 868102416 3 -195461235 -180651308 -250893512 -232183484 741194405 748153230 1 -583374820 -573301094 2 -289487516 -278362438 -617984192 -600701104 3 361103576 377771047 -629713150 -625261223 760487909 765234419 2 -789...
output:
1 4 -336270587 -252002330 -186846904 848243159 1 3 -250893512 -195461235 741194405 1 1 -583374820 1 2 -617984192 -289487516 1 3 -629713150 361103576 760487909 1 2 -789944592 -103045325 1 1 756732794 1 4 -428947266 -243873198 439377407 512729535 1 3 -832490738 -677551837 366281659 1 6 -869814878 -501...
result:
ok ok, tt = 18139
Test #11:
score: -100
Wrong Answer
time: 28ms
memory: 13984kb
input:
18100 8 598403417 795720309 -373919856 -307381953 199626892 235156246 -217973856 -203235401 516184634 548146965 556458253 612829986 -686678416 -587302321 -251190508 -105682769 6 -526414856 -462880667 -734369052 -596753646 114814523 150451126 -10532542 21149560 -892168032 -828869761 -663573167 -62124...
output:
1 7 -686678416 -373919856 -217973856 199626892 516184634 556458253 795720309 1 5 -892168032 -663573167 -526414856 -10532542 114814523 1 1 265590649 1 6 -974272520 -859851492 -694051917 -139684712 -35213337 72700218 1 7 -874717487 -726871981 430693526 566260856 637021235 904610397 963371105 1 4 -8258...
result:
wrong answer test 8630: expected 1, found 2