QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#140869#5159. Justice ServedRetiredButNotTired#WA 338ms32872kbC++171.9kb2023-08-16 21:53:472023-08-16 21:53:49

Judging History

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

  • [2023-08-16 21:53:49]
  • 评测
  • 测评结果:WA
  • 用时:338ms
  • 内存:32872kb
  • [2023-08-16 21:53:47]
  • 提交

answer

// Hey there.. I love you <3
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

mt19937 rnd(time(nullptr));

#define all(x) x.begin(), x.end()
#define f first
#define s second

const int N = 1 << 20, M = 705, mod = 1e9 + 7;

#define node int
const node defaultNode = 0;
node segTree[N << 1];
int segTreeSize = N;

node merge(node x, node y) { return max(x, y); }

void add(int i, node x) {
    i += segTreeSize;
    segTree[i] = max(segTree[i], x);
    while (i >>= 1) segTree[i] = merge(segTree[i << 1], segTree[(i << 1) + 1]);
}

node findSeg(int lo = 0, int ro = segTreeSize, int l = 0, int r = segTreeSize, int x = 1) {
    if (l >= ro || r <= lo) return defaultNode;
    if (l >= lo && r <= ro) return segTree[x];
    int mid = (l + r) >> 1;
    return merge(findSeg(lo, ro, l, mid, x << 1), findSeg(lo, ro, mid, r, (x << 1) + 1));
}

int n, ans[N];
pair<pair<int, int>, int> a[N];

void work() {
    
    cin >> n;
    
    map<int, int> mp;
    
    for (int i = 0; i < n; ++i) {
        cin >> a[i].f.f >> a[i].f.s;
        mp[a[i].f.f], mp[a[i].f.s];
    }
    
    int c = 0;
    for (auto &it: mp) it.s = c++;
    for (int i = 0; i < n; ++i)
        a[i] = {{mp[a[i].f.f], -mp[a[i].f.s]}, i};
    
    sort(a, a + n);
    for (int i = 0; i < n; ++i) {
        int r = -a[i].f.s;
        
        int score = findSeg(r) + 1;
        
        ans[a[i].s] = score;
        add(r, score);
    }
    
    for (int i = 0; i < n; ++i)
        cout << ans[i] - 1 << " ";
    cout << endl;
    
}


void init() {
    cin.tie(nullptr);
    istream::sync_with_stdio(false);
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
    
    
}

int main() {
    init();
    
    int testCases = 1;
    //cin >> testCases;
    while (testCases--) work();
    
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 7708kb

input:

4
2 8
1 7
4 5
5 2

output:

0 0 1 2 

result:

ok single line: '0 0 1 2 '

Test #2:

score: 0
Accepted
time: 0ms
memory: 9812kb

input:

5
2 4
3 3
2 2
4 2
4 1

output:

0 1 1 2 3 

result:

ok single line: '0 1 1 2 3 '

Test #3:

score: -100
Wrong Answer
time: 338ms
memory: 32872kb

input:

200000
75760147 173015388
62879760 211229046
6728658 106668560
29476341 129401393
30531505 130450085
39792769 139780734
59486082 221617335
12447225 112582555
94207716 117434450
68962063 193352291
13519090 113644734
60611935 218232526
77901558 166662816
40316254 140281744
39094390 138994435
49921965 ...

output:

51067 25775 6 14 12 14 19015 9 88306 37703 9 21158 55423 15 13 16 12 24879 15 7 8 45768 24224 14 11 55424 9 7 12683 15 65167 14 1 33107 19 20827 81112 10 1963 98792 89739 13 95821 44266 89326 16 8 16 4 8131 16033 8 9 90497 70197 36711 14 15 46836 39837 38641 13 53674 7 16 4 15 18 12 83782 15935 9 4 ...

result:

wrong answer 1st lines differ - expected: '51062 25770 5 10 10 12 19010 7...59 9 12 84254 91909 88054 9 7 7', found: '51067 25775 6 14 12 14 19015 9...4 14 84259 91914 88059 14 12 8 '