QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#461738#6880. Operation HopemdubaAC ✓971ms27840kbC++208.5kb2024-07-03 00:32:202024-07-03 00:32:20

Judging History

你现在查看的是最新测评结果

  • [2024-07-03 00:32:20]
  • 评测
  • 测评结果:AC
  • 用时:971ms
  • 内存:27840kb
  • [2024-07-03 00:32:20]
  • 提交

answer

//#pragma comment(linker, "/stack:20000000")
//#pragma GCC optimize("Ofast,O3,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,avx2,bmi,bmi2,popcnt,lzcnt")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define se second
#define fi first
#define ld long double
#define ss size()
#define pb push_back
#define mp make_pair
#define ins insert
#define ll long long
#define ull unsigned long long
#define y1 y12313312312
#define vd vasvsadasdasfdasf
#define endl '\n'
#define gcd __gcd
#define b_p __builtin_popcountll
#define next nqweqweeqeqe
#define prev ppawfawfpfaw
#define pii pair < int, int >
#define pdd pair < double, double >
#define vi vector < int >
#define vpii vector < pii >
#define vpdd vector < pdd >
#define si set < int >
#define spii set < pii >
#define mii map < int, int >
#define umii unordered_map < int, int >
#define msi multiset < int >
#define qi queue < int >
#define qpii queue < pii >
#define mci map < char, int >
#define mdi map < double, int >
#define all(x) x.begin(), x.end()
#define mems(x, y) memset(x, y, sizeof x)
#define srt(x, y) sort(x + 1, x + y + 1)
#define rvs(x, y) reverse(x + 1, x + y + 1)
#define FOR(i, x, y) for (int i = x; i <= y; i++)
#define FOR1(i, x, y, z) for(int i = x; i <= y; i += z)
#define ROF(i, x, y) for (int i = x; i >= y; i--)
#define ROF1(i, x, y, z) for (int i = x; i >= y; i -= z)
#define uniq(x); sort(all(x)); x.resize(unique(all(x)) - x.begin());
#define mid ((tl + tr) >> 1)
#define LS v + v, tl, mid
#define RS v + v + 1, mid + 1, tr
#define int ll

using namespace std;
using namespace __gnu_pbds;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T, class U> bool emin(T& a, const U& b) { return b < a ? a = b, 1 : 0; } // set a = min(a,b)
template <class T, class U> bool emax(T& a, const U& b) { return a < b ? a = b, 1 : 0; } // set a = max(a,b)
template <class T, class U> void erase(T& t, const U& u) { // don't erase
    auto it = t.find(u); //assert(it != end(t));
    if (it != t.end()) t.erase(it);
}

inline namespace FileIO {
	void setIn(string s)  { freopen(s.c_str(),"r",stdin); }
	void setOut(string s) { freopen(s.c_str(),"w",stdout); }
	void setIO(string s = "") {
		//cin.tie(0)->sync_with_stdio(0); // unsync C / C++ I/O streams
		ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
		// cin.exceptions(cin.failbit);
		// throws exception when do smth illegal
		// ex. try to read letter into int
		if (s.ss) setIn(s+".in"), setOut(s+".out"); // for old USACO
	}
}

int MOD = 1e9 + 33;
#ifndef int
struct Mint
{
    private:
        int normal(int x) { if (x >= MOD) x -= MOD; if (x < 0) x += MOD; return x;}
        int power(int x, int y) { int res = 1; for (;y;y >>= 1, x = (x * x) % MOD) if (y & 1) res = (res * x) % MOD; return res;}
    public:

        int x;
        Mint():x(0){}
        Mint(int y):x(normal(y)){}
        Mint operator -()const {return Mint(MOD - x);}
        Mint operator +(const Mint y) {return Mint(x + y.x);}
        Mint operator -(const Mint y) {return Mint(x - y.x);}
        Mint operator *(const Mint y) {return Mint(int((ll)x * y.x % MOD));}
        Mint operator *(const int y) {return Mint(int((ll)x * y % MOD));}
        Mint operator /(const Mint y) {return Mint(int((ll)x * power(y.x, MOD - 2) % MOD));}
        Mint &operator =(const Mint y) {x = normal(y.x); return *this;}
        Mint &operator +=(const Mint y) {x = normal(x + y.x); return *this;}
        Mint &operator -=(const Mint y) {x = normal(x - y.x); return *this;}
        Mint &operator *=(const Mint y) {x = int((ll)x * y.x % MOD); return *this;}
        Mint &operator *=(const int y) {x = int((ll)x * y % MOD); return *this;}
        Mint &operator /=(const Mint y) {x = int((ll)x * power(y.x, MOD - 2) % MOD); return *this;}
        bool operator ==(const int y) {return x == y;}
};
ostream& operator << (ostream& out, const Mint& x){ out << x.x; return out;}
#endif // int
template < typename T, typename TT > ostream& operator << (ostream& out, const pair < T, TT>& p) {out << p.fi << " " << p.se; return out;}
template < typename T, typename TT > pair < T, TT > operator + (const pair < T, TT >& p1, const pair < T, TT >& p2) {return make_pair(p1.fi + p2.fi, p1.se + p2.se);}
template < typename T, typename TT > pair < T, TT > operator += (pair < T, TT >& p1, const pair < T, TT>& p2) {p1.fi += p2.fi; p1.se += p2.se; return p1;}

int bp (int x, int y)
{
    ll res = 1;
    for (; y; y >>= 1, x = (x * x))
        if (y & 1) res = (res * x);
    return res;
}
ll bpm(ll x, ll y, ll md = MOD)
{
    ll res = 1;
    for (; y; y >>= 1, x = (x * x) % md)
        if (y & 1) res = (res * x) % md;
    return res;
}
/*
inline void normal(ll &x, int md = MOD)
{
    if (x < md && x >= 0) return;
    x %= md;
    if (x < 0) x += md;
}
inline int MUL(ll x, ll y, int md = MOD)
{
    normal(x, md); normal(y, md);
    return (x * y) % md;
}
inline int SQ(ll x, int md = MOD)
{
    normal(x, md);
    return MUL(x, x, md);
}
inline int ADD(int x, int y, int md = MOD)
{
    normal(x, md); normal(y, md);
    return (x + y >= md ? x + y - md : x + y);
}
inline int SUB(int x, int y, int md = MOD)
{
    normal(x, md); normal(y, md);
    x -= y;
    if (x < 0) x += md;
    return x;
}
inline int DIV(ll x, ll y, int md = MOD)
{
    normal(x, md); normal(y, md);
    y = bpm(y, md - 2, md);
    return MUL(x, y, md);
}*/

bool is_prime(int x)
{
    if (x <= 1) return 0;
    for (int i = 2; i * i <= x; i++) if (x % i == 0) return 0;
    return 1;
}

inline int cd(char c){return c - '0';}
inline char cc(int x){return x + '0';}
inline char cb(int x){return x + 'A';}
inline int cn(char c){return c - 'A';}
inline int diff(int x, int y){return abs(x - y);}
inline void abandon(){cout << "NO";exit(0);}
inline int rng(int l, int r){return (rnd() % (r - l + 1) + l);}
inline int pw2(int i){return (1 << i);}
inline bool bit(int mask, int i){return ((mask >> i) & 1);}
inline int lcm(int x, int y) {return (x / gcd(x, y)) * y;}
inline int sign(int x) {return (x < 0 ? -1 : !!x);}
inline void coutmask(int mask, int sz) {FOR (i, 0, sz - 1) cout << bit(mask, i);}

const ll INF = 1e15 + 7;
const int N = 1e5 + 40, T = 4 * N, logN = (int)log2(N) + 2, Nlog = N * logN * 2, basic = 41/*379999*/, inf = 1e9 + 7, Mod = 998244353, /*NWSE or ULDR*/sx[4] = {-1, 0, 1, 0}, sy[4] = {0, -1, 0, 1}, mod = 1e9 + 3;
const int dx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dy[8] = {1, 0, -1, 1, -1, 1, 0, -1}, sqN = (int)sqrt(N), BL = 316, BL2 = 1000;
const double eps = 1e-12, pi = acos(-1);

int n, m, r, l, e, id, mx = -inf, mn = inf, w, timer, tst, delta = 2e8 + 1;

int a[N], b[N], c[N], a1[N], b1[N], c1[N], d[N];
spii Sa, Sb, Sc;

int f;

void solve()
{
    ll x = 0, y = 0, z = 0;

    cin >> n;
    Sa.clear();
    Sb.clear();
    Sc.clear();
    FOR (i, 1, n)
    {
        cin >> a[i] >> b[i] >> c[i] >> a1[i] >> b1[i] >> c1[i];
        Sa.ins({a[i], i});
        Sb.ins({b[i], i});
        Sc.ins({c[i], i});
        d[i] = 0;
    }

    d[0] = 1;
    f = INF;
    while (1)
    {
        int xa = (Sa.rbegin() -> fi) - (Sa.begin() -> fi);
        int xb = (Sb.rbegin() -> fi) - (Sb.begin() -> fi);
        int xc = (Sc.rbegin() -> fi) - (Sc.begin() -> fi);
        mx = max({xa, xb, xc});
        emin(f, mx);/*
        cout << mx << endl;
        for (auto i : Sa) cout << i.fi << " ";
        cout << endl;
        for (auto i : Sb) cout << i.fi << " ";
        cout << endl;
        for (auto i : Sc) cout << i.fi << " ";
        cout << endl << endl;*/
        int i = 0;
        if (xa == mx)
        {
            i = Sa.begin() -> se;
        }
        else if (xb == mx)
        {
            i = Sb.begin() -> se;
        }
        else if (xc == mx)
        {
            i = Sc.begin() -> se;
        }
        if (d[i]) break;
        d[i] = 1;
        erase(Sa, mp(a[i], i));
        Sa.ins({a1[i], i});
        erase(Sb, mp(b[i], i));
        Sb.ins({b1[i], i});
        erase(Sc, mp(c[i], i));
        Sc.ins({c1[i], i});
    }
    cout << f << endl;
}

signed main()
{
    int x, y, z;
    //setprecision(9);
    #ifdef LOCAL
    setIn("input.txt");
    setOut("output.txt");
    #else
    setIO();
    #endif

    int _ = 1;
    cin >> _;
    for (int i = 1; i <= _; ++i)
    {
        //cout << "Case " << i << ": ";
        solve();
        //cout << "\n";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 971ms
memory: 27840kb

input:

99
1000
532114032 55099632 197592060 601440117 964448551 693620489
68503446 149314803 308777541 408078601 977772348 978400861
185066959 236214410 460480442 842502015 709303988 675932475
793016330 161748857 511444978 852914351 281720292 552030608
9982160 15933748 8254470 175080600 567563770 461489051...

output:

982758431
499804923
99919477
99613700
99922111
99914205
99946480
99849310
114469
959350057
499447574
99965775
99807900
99959755
99858165
99900104
99981039
114408
983543586
499348157
99948914
99680790
99821819
99927070
99827404
99854234
114334
984379893
499383664
99973920
99536294
99818752
99826757
9...

result:

ok 99 lines