QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#99035#5504. Flower GardenKHINWA 3604ms121320kbC++5.6kb2023-04-21 09:09:212023-04-21 09:09:23

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-21 09:09:23]
  • 评测
  • 测评结果:WA
  • 用时:3604ms
  • 内存:121320kb
  • [2023-04-21 09:09:21]
  • 提交

answer

# define NDEBUG

# include <cstdlib>
# include <cassert>
# include <cstring>
# include <vector>
# include <algorithm>
# include <iostream>
# include <istream>
# include <ostream>

namespace khin {
  using namespace std;
  namespace ucup {
    inline namespace source {}
    namespace ucup1 {
      namespace stage03 {
        namespace f { void main(); }
      }
    }
  }
}

int main() { khin::ucup::ucup1::stage03::f::main(); }

namespace khin::ucup::ucup1::stage03::f {
  namespace test_case {
    constexpr uint n_max(33'333), q_max(100'000);
    inline uint next_index();
    inline void set(uint, uint);
    inline void add(uint, uint);
    class segment_tree {
      constexpr static uint lg_max = __lg(3 * n_max + 1) + 1;
      uint lg, s[1 << (lg_max + 1)], t[1 << (lg_max + 1)];
      public:
      segment_tree() {}
      void assign(uint const n) {
        lg = __lg(3 * n + 1) + 1;
        for (uint i(0); i != 1u << lg; ++i) {
          s[1 << lg | i] = next_index();
          t[1 << lg | i] = next_index();
          assert(s[1 << lg | i] == (i << 1 | 0));
          assert(t[1 << lg | i] == (i << 1 | 1));
          if (1 <= i && i <= 3 * n) set(s[1 << lg | i], 1);
          add(t[1 << lg | i], s[1 << lg | i]);
        }
        for (uint i((1u << lg) - 1); i; --i) {
          s[i] = next_index(), t[i] = next_index();
          add(s[i << 1 | 0], s[i]), add(s[i << 1 | 1], s[i]);
          add(t[i], t[i << 1 | 0]), add(t[i], t[i << 1 | 1]);
        }
        assert(t[1] == 2 * (1u << (lg + 1)) - 3);
      }
      void adds(uint l, uint r, uint const x) const {
        --l |= 1 << lg, ++r |= 1 << lg;
        while ((l ^ r) >> 1) {
          if ((l & 1) == 0) add(s[l ^ 1], x);
          if ((r & 1) == 1) add(s[r ^ 1], x);
          l >>= 1, r >>= 1;
        }
      }
      void addt(uint l, uint r, uint const x) const {
        --l |= 1 << lg, ++r |= 1 << lg;
        while ((l ^ r) >> 1) {
          if ((l & 1) == 0) add(x, t[l ^ 1]);
          if ((r & 1) == 1) add(x, t[r ^ 1]);
          l >>= 1, r >>= 1;
        }
      }
      void addr(uint const a, uint const b, uint const c, uint const d) const {
        uint const x(next_index());
        assert(x >= 2 * (1u << (lg + 1)) - 2);
        assert(x - 2 * (1u << (lg + 1)) + 2 < q_max);
        adds(a, b, x), addt(c, d, x);
      }
    };
    class graph {
      constexpr static uint v_max
        = 2 * (1 << (__lg(3 * n_max + 1) + 2)) + q_max;
      struct vertex0 { vector<uint> t; uint index, low, scc; uint val; };
      struct vertex1 { vector<uint> s, t; uint sum; bool vis; };
      vertex0 v0[v_max]; uint p, index, num; vertex1 v1[v_max + 1];
      void tarjan(uint const x) {
        static uint stk[v_max], *top(stk);
        v0[x].low = v0[x].index = ++index, *top++ = x;
        for (uint const t : v0[x].t)
          if (!v0[t].index) tarjan(t), v0[x].low = min(v0[x].low, v0[t].low);
          else if (!v0[t].scc) v0[x].low = min(v0[x].low, v0[t].index);
        if (v0[x].low == v0[x].index)
        { ++num; while (v0[*--top].scc = num, *top != x); }
      }
      uint sums(uint const x) {
        if (v1[x].vis) return 0; else v1[x].vis = true;
        uint res(v1[x].sum);
        for (uint const s : v1[x].s) res += sums(s);
        return res;
      }
      uint sumt(uint const x) {
        if (v1[x].vis) return 0; else v1[x].vis = true;
        uint res(v1[x].sum);
        for (uint const t : v1[x].t) res += sumt(t);
        return res;
      }
      public:
      void clear() {
        fill(v0, v0 + p, vertex0());
        fill(v1 + 1, v1 + num + 1, vertex1());
        num = index = p = 0;
      }
      uint next_index() { return p++; }
      void set(uint const x, uint const v) { this->v0[x].val = v; }
      void add(uint const s, uint const t) { v0[s].t.push_back(t); }
      string solve(uint const n) {
        for (uint i(0); i < p; ++i) if (!v0[i].index) tarjan(i);
        for (uint i(0); i < p; ++i) v1[v0[i].scc].sum += v0[i].val;
        uint tot(0);
        for (uint i(1); i <= num; ++i)
          if ((tot += v1[i].sum) >= n && tot <= 2 * n) {
            string s(3 * n, ' ');
            for (uint j(1); j <= 3 * n; ++j)
              s[j - 1] = v0[j << 1 | 0].scc <= i ? 'F' : 'R';
            return s;
          }
        for (uint i(1); i <= num; ++i) if (v1[i].sum > n) {
          if (sums(i) <= 2 * n) {
            string s(3 * n, ' ');
            for (uint j(1); j <= 3 * n; ++j)
              s[j - 1] = v1[v0[j << 1 | 0].scc].vis ? 'F' : 'R';
            for (uint j(1); j <= num; ++j) v1[j].vis = false;
            return s;
          }
          for (uint j(1); j <= num; ++j) v1[j].vis = false;
          if (sumt(i) <= 2 * n) {
            string s(3 * n, ' ');
            for (uint j(1); j <= 3 * n; ++j)
              s[j - 1] = v1[v0[j << 1 | 0].scc].vis ? 'F' : 'R';
            for (uint j(1); j <= num; ++j) v1[j].vis = false;
            return s;
          }
          for (uint j(1); j <= num; ++j) v1[j].vis = false;
        }
        return string();
      }
    };
    uint n, q; segment_tree seg; graph g;
    inline uint next_index() { return g.next_index(); }
    inline void set(uint const x, uint const v) { g.set(x, v); }
    inline void add(uint const s, uint const t) { g.add(s, t); }
    void main() {
      cin >> n >> q, seg.assign(n);
      for (uint i(0); i < q; ++i) {
        uint a, b, c, d;
        cin >> a >> b >> c >> d;
        seg.addr(a, b, c, d);
      }
      string const ans(g.solve(n));
      if (ans.empty()) cout << "NIE" << endl;
      else cout << "TAK" << endl << ans << endl;
      g.clear();
    }
  }
  void main() {
    uint z; cin >> z;
    for (uint i(1); i <= z; ++i) test_case::main();
  }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 7ms
memory: 61980kb

input:

2
1 3
1 1 2 2
1 2 3 3
1 1 3 3
1 3
1 1 2 2
2 2 3 3
3 3 1 1

output:

TAK
RRF
NIE

result:

ok good!

Test #2:

score: 0
Accepted
time: 3604ms
memory: 121320kb

input:

10
33333 100000
28701 40192 93418 95143
95902 97908 78378 78461
36823 44196 22268 23996
23977 24786 33315 48829
83965 90411 4923 8445
20235 21177 32543 47454
29598 35414 72477 73049
2014 12632 42163 46466
64305 65518 98825 99552
32331 41625 92772 96224
26500 54122 76990 77126
18249 20335 31165 36080...

output:

NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE

result:

ok good!

Test #3:

score: 0
Accepted
time: 2761ms
memory: 110568kb

input:

10
33333 100000
15207 33614 66276 66276
97173 97173 67589 73960
19673 36626 65207 65207
89825 98169 27079 27079
56067 56966 7560 7560
18170 35477 18752 18752
32621 36748 34460 34460
61595 61700 14117 14117
32395 36710 9064 9064
13172 13172 1728 4640
40462 41878 47171 47171
76965 82414 5767 5767
9225...

output:

TAK
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF...

result:

ok good!

Test #4:

score: 0
Accepted
time: 2527ms
memory: 110944kb

input:

10
33333 100000
2646 2646 6430 6446
82226 82231 15128 15132
877 877 85831 88474
51389 79196 37573 37573
38030 38030 14248 14280
63032 68489 81074 81074
46468 46468 7403 7487
19864 20058 97979 97979
71640 71833 8558 8558
12121 12434 82481 82481
32901 32901 1899 2162
65312 77886 75969 75974
87983 8798...

output:

TAK
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFRRFFFFRFFRRFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF...

result:

ok good!

Test #5:

score: -100
Wrong Answer
time: 1075ms
memory: 61932kb

input:

87005
1 3
1 1 2 2
1 2 3 3
1 1 3 3
1 3
1 1 2 2
2 2 3 3
3 3 1 1
1 1
1 3 2 3
1 2
1 1 2 2
2 2 1 1
1 2
1 3 1 1
1 1 1 3
4 20
3 5 6 12
4 5 7 11
1 1 2 2
3 4 7 12
3 5 10 10
3 5 8 8
4 4 9 11
4 4 7 7
1 1 9 10
3 4 6 9
3 5 11 12
3 3 7 9
3 5 2 2
4 5 2 2
1 1 7 11
1 1 10 10
3 5 7 8
4 4 2 2
1 1 2 2
4 5 8 10
4 12
11 ...

output:

TAK
RRF
NIE
TAK
RFF
TAK
FFR
NIE
TAK
RFRRRRFRFFRR
TAK
FFRRFFRRRRRR
NIE
TAK
FFFFRRRRRRRFRRR
TAK
FRRRRRRRRFFF
TAK
FFFRRRRRRRRF
TAK
FFFFFRRRRRRRRRR
TAK
FFRRRRRRRRFF
TAK
FFRRFFRRRFRRRRR
NIE
TAK
FFFFRRRRRRRR
NIE
TAK
FRFFFRRFF
NIE
TAK
FFFRRRRRR
TAK
RRRRRRFFFRRF
TAK
RRFFRFRFFFFRRRR
TAK
RRRRRRRFFFFR
NIE
TAK
...

result:

wrong answer odpowiedz nie spelnia wymogow!