QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#776666#7859. BladestormguodongWA 119ms3628kbC++174.1kb2024-11-23 20:01:112024-11-23 20:01:12

Judging History

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

  • [2024-11-23 20:01:12]
  • 评测
  • 测评结果:WA
  • 用时:119ms
  • 内存:3628kb
  • [2024-11-23 20:01:11]
  • 提交

answer

#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
int n,k;
class Block{
    public:
        vector<pair<int,int>> ans;
        vector<int> nxt;
        vector<int> mark;
        int n;
        bool exist = 0;
        pair<int,int> startv;
        Block(int _n){
            n = _n;
            exist = 0;
            ans.resize(k + 1);
            nxt.resize(_n);
            mark.resize(_n);
        }
        void calc(){
            for(int i = n - 1; i >= 0; --i){
                if(mark[i])
                    nxt[i] = i;
                else if(i == n - 1)
                    nxt[i] = 1e9;
                else
                    nxt[i] = nxt[i + 1];
            }
            for(int p = 0; p < k; ++p){
                int st = p,cnt = 0,flag = 0;
                while(1){
                    if(st == n-1 || nxt[st + 1] == 1e9){
                        ans[p] = make_pair(cnt,st);
                        break;
                    }
                    if(st + k >= n){
                        ans[p] = make_pair(cnt + 1,st + k);
                        break;
                    }
                    if(nxt[st + k] == nxt[st + 1]){
                        st = nxt[st + 1];
                    }
                    else{
                        st = st + k;
                    }
                    ++cnt;
                }
            }
            int p = nxt[0];
              int st = p,cnt = 0,flag = 0;
                while(1){
                    if(st == n-1 || nxt[st + 1] == 1e9){
                        startv = make_pair(cnt,st);
                        break;
                    }
                    if(st + k >= n){
                        startv = make_pair(cnt + 1,st + k);
                        break;
                    }
                    if(nxt[st + k] == nxt[st + 1]){
                        st = nxt[st + 1];
                    }
                    else{
                        st = st + k;
                    }
                    ++cnt;
                }
        }
        void add(int x){
            exist = 1;
            if(mark[x])
                return;
            mark[x] = 1;
            calc();
        }
        pair<int,int> getAns(int st){
            if(st == nxt[0]){
                return startv;
            }
            return ans[st];
        }
        bool Exist(){
            return exist;
        }
};
signed main()
{
    #ifdef NICEGUODONG
        freopen("data.in","r",stdin);
        freopen("wa.out","w",stdout);
    #endif
    ios::sync_with_stdio(false);
    int T;
    cin >> T;
    while(T--){
        cin >> n >> k;
        int len;
        len = sqrt(n)  + 1;
        // len = n + 1;
        vector<Block> block((n + len - 1) / len + 1, Block(len));
        int maxx = 0;

        for(int i = 1; i <= n; ++i){
            int x;
            cin >> x;
            maxx = max(maxx,x);
            block[x / len].add(x % len);
            int cur = 0,ans = 0,id = 0,ext = 0;
            while(cur < maxx){
                int l = id * len, r = id * len + len - 1;
                if(block[id].exist == 0 || cur >= r){
                    ++id;
                    ext = 1;
                    continue;
                }
                if(ext == 1){
                    ext = 0;
                    ans++;
                    cur = block[id].nxt[0] + l;
                }
                if(cur >= l){
                    auto [fee,nxt] = block[id].getAns(cur - l);
                    ans += fee;
                    cur = nxt + l;
                }
                else if(cur + k >= r){
                    cur += k;
                    ++ans;
                }
                else{
                    cur = max(cur + k,block[id].nxt[0] + l);
                    ++ans;
                    auto t = block[id].getAns(cur - l);
                    auto &[fee,nxt] = t;
                    ans += fee;
                    cur = nxt + l;
                }
                ++id;
            }
            cout << ans << " ";
        }
        cout << '\n';
    }

}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3628kb

input:

3
7 2
4 7 3 6 1 2 5
11 3
10 7 4 9 6 8 5 1 3 2 11
9 2
1 2 3 7 8 9 4 5 6

output:

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

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 119ms
memory: 3616kb

input:

40319
1 1
1
2 1
1 2
2 1
2 1
2 2
1 2
2 2
2 1
3 1
1 2 3
3 1
1 3 2
3 1
2 1 3
3 1
2 3 1
3 1
3 1 2
3 1
3 2 1
3 2
1 2 3
3 2
1 3 2
3 2
2 1 3
3 2
2 3 1
3 2
3 1 2
3 2
3 2 1
3 3
1 2 3
3 3
1 3 2
3 3
2 1 3
3 3
2 3 1
3 3
3 1 2
3 3
3 2 1
4 1
1 2 3 4
4 1
1 2 4 3
4 1
1 3 2 4
4 1
1 3 4 2
4 1
1 4 2 3
4 1
1 4 3 2
4 1
...

output:

1 
1 2 
1 2 
1 1 
1 1 
1 2 3 
1 2 3 
1 2 3 
1 2 3 
1 2 3 
1 2 3 
1 1 2 
1 2 2 
1 1 2 
1 2 2 
1 2 2 
1 2 2 
1 1 1 
1 1 1 
1 1 1 
1 2 1 
1 1 1 
1 2 1 
1 2 3 4 
1 2 3 4 
1 2 3 4 
1 2 3 4 
1 2 3 4 
1 2 3 4 
1 2 3 4 
1 2 3 4 
1 2 3 4 
1 2 3 4 
1 2 3 4 
1 2 3 4 
1 2 3 4 
1 2 3 4 
1 2 3 4 
1 2 3 4 
1 2 3 4...

result:

wrong answer 21st lines differ - expected: '1 1 1', found: '1 2 1 '