QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#455621#7626. Quake and RebuildRong7WA 0ms5744kbC++146.1kb2024-06-26 16:53:092024-06-26 16:53:09

Judging History

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

  • [2024-11-20 20:27:49]
  • hack成功,自动添加数据
  • (/hack/1219)
  • [2024-06-26 16:53:09]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:5744kb
  • [2024-06-26 16:53:09]
  • 提交

answer

// Not afraid to dark.

#include <bits/stdc++.h>
using namespace std;

clock_t start_time, end_time;
#define GET_START start_time = clock ();
#define GET_END end_time = clock (); fprintf (stderr, "TIME COSSEMED : %0.3lf\n", 1.0 * (end_time - start_time) / CLOCKS_PER_SEC);
#define inline __inline__ __attribute__ ((always_inline))

namespace io {
    int read_pos, read_dt; char read_char;
    inline int read (int &p = read_pos){
        p = 0, read_dt = 1; read_char = getchar ();
        while (! isdigit (read_char)){
            if (read_char == '-')
                read_dt = - 1;
            read_char = getchar ();
        }
        while (isdigit (read_char)){
            p = (p << 1) + (p << 3) + read_char - 48;
            read_char = getchar ();
        }
        return p = p * read_dt;
    }
    int write_sta[65], write_top;
    inline void write (int x){
        if (x < 0)
            putchar ('-'), x = - x;
        write_top = 0;
        do
            write_sta[write_top ++] = x % 10, x /= 10;
        while (x);
        while (write_top)
            putchar (write_sta[-- write_top] + 48);
    }
}

const int N = 2e5, T = 450;

int n, m;

namespace BLOCK {
    int sq, len, block[N + 5], delta[T + 5], bl[T + 5], br[T + 5];
    int f[N + 5], nx[N + 5], cs[N + 5];
    bool ton[N + 5];
    inline void rebuild (int x){
        for (int i = bl[x];i <= br[x];++ i){
            if (f[i] - delta[x] < bl[x])
                nx[i] = max (0, f[i] - delta[x]), cs[i] = 1;
            else
                nx[i] = nx[f[i] - delta[x]], cs[i] = cs[f[i] - delta[x]] + 1;
        }
    }
    inline void build (){
        sq = len = sqrt (n);
        while (sq * len < n)
            ++ len;
        for (int i = 1;i <= sq;++ i){
            bl[i] = br[i - 1] + 1;
            br[i] = min (n, bl[i] + len - 1);
            for (int j = bl[i];j <= br[i];++ j)
                block[j] = i;
            delta[i] = 0;
            rebuild (i);
        }
    }
    inline int nex (int x){
        if (delta[block[x]] < len)
            return nx[x];
        return max (0, f[x] - delta[block[x]]);
    }
    inline int F (int x){
        return max (0, f[x] - delta[block[x]]);
    }
    inline int cos (int x){
        if (delta[block[x]] < len)
            return cs[x];
        return 1;
    }
    vector < int > pt[T + 5];
} using namespace BLOCK;

#define assert(x) {if (x == true) puts ("in"); exit (0);}

signed main (){
    GET_START

    n = io::read () - 1, io::read (m);
    for (int i = 1;i <= n;++ i)
        f[i] = io::read () - 1;
    build ();
    while (m --){
        int op = io::read ();
        if (op == 1){
            int l = io::read () - 1, r = io::read () - 1, d = io::read ();
            for (int i = l;i <= min (r, br[block[l]]);++ i)
                f[i] = max (0, f[i] - d);
            rebuild (block[l]);
            for (int i = block[l] + 1;i < block[r];++ i){
                delta[i] += d;
                if (delta[i] < len)
                    rebuild (i);
            }
            if (block[l] ^ block[r]){
                for (int i = bl[block[r]];i <= r;++ i)
                    f[i] = max (0, f[i] - d);
                rebuild (block[r]);
            }
        } else {
            int N = io::read (), tx, ans = 0, cnt = N;
            while (N --){
                tx = io::read () - 1;
                pt[block[tx]].push_back (tx);
            }
            for (int i = sq;i >= 1;-- i)
                if (! pt[i].empty ()){
                    for (int x : pt[i]){
                        assert (x >= bl[i] && x <= br[i]);
                        ton[x] = true;
                    }
                    vector < int > lins;
                    for (int x : pt[i])
                        if (ton[x]){
                            ton[x] = false;
                            lins.push_back (x);
                        } else
                            -- cnt;
                    assert (cnt == 0);
                    pt[i] = lins, lins.clear ();
                    if (cnt == 1){
                        ++ ans;
                        break;
                    }
                    bool tag = false;
                    for (int x : pt[i]){
                        assert (nex (x) <= bl[i] && nex (x) >= 0);
                        if (! ton[nex (x)])
                            ton[nex (x)] = true;
                        else
                            tag = true;
                    }
                    for (int x : pt[i])
                        ton[nex (x)] = false;
                    if (! tag){
                        for (int x : pt[i]){
                            pt[block[nex (x)]].push_back (x);
                            ans += cos (x);
                        }
                        pt[i].clear ();
                    } else {
                        int minx = br[i];
                        for (int x : pt[i])
                            ton[x] = true, minx = min (minx, x);
                        cnt -= (int) pt[i].size ();
                        pt[i].clear ();
                        for (int j = br[i];j >= bl[i];-- j)
                            if (ton[j]){
                                ++ ans;
                                if (j > minx || cnt > 0){
                                    assert (F (j) >= 0);
                                    if (F (j) >= bl[i])
                                        ton[F (j)] = true;
                                    else {
                                        pt[block[F (j)]].push_back (F (j));
                                        ++ cnt;
                                    }
                                    minx = min (minx, F (j));
                                }
                            }
                        for (int j = bl[i];j <= br[i];++ j)
                            ton[j] = false;
                    }
                }
            if (! pt[0].empty ())
                ++ ans, pt[0].clear ();
            io::write (ans), puts ("");
        }
    }

    GET_END
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 5744kb

input:

4 5
1 2 2
2 2 1 4
1 2 3 1
2 3 2 3 4
1 4 4 1
2 2 3 4

output:

in

result:

wrong answer 1st lines differ - expected: '3', found: 'in'