답안 #815749

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
815749 2023-08-08T20:52:11 Z exodus_ Ekoeko (COCI21_ekoeko) C++14
20 / 110
51 ms 4564 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+1;
int segtree[4*N] = {0};
int freq[30];
vector<char>urt;
deque<int>dex[30];
vector<int>isi;
void update(int idx, int low, int high, int val) {
    if(high==low && low==val) {
        segtree[idx]=1;
        return;
    }
    if(val<low || val>high) return;
    int mid=(low+high)/2;
    update(2*idx,low,mid,val);
    update(2*idx+1,mid+1,high,val);
    segtree[idx] = segtree[2*idx]+segtree[2*idx+1];
}
int quer(int idx, int low, int high, int l, int r) {
    if(low>=l && high<=r) {
        return segtree[idx];
    }
    if(low>r || high<l) return 0;
    int mid = (low+high)/2;
    int left = quer(2*idx,low,mid,l,r);
    int right = quer(2*idx+1,mid+1,high,l,r);
    return left+right;
}
int main() {
    int n;
    cin >> n;
    n*=2;
    string asli;
    cin >> asli;
    for(int i=0; i<asli.size(); i++) {
        freq[asli[i]-97]++;
    }
    for(int i=0; i<n; i++) {
        if(freq[asli[i]-97]>0) {
            urt.push_back(asli[i]);
            freq[asli[i]-97]-=2;
        }
    }
    int sizeurt=urt.size();
    for(int i=0; i<sizeurt; i++) {
        urt.push_back(urt[i]);
    }
    for(int i=0; i<n; i++) {
        dex[urt[i]-97].push_back(i);
    }
    for(int i=0; i<n; i++) {
        isi.push_back(dex[asli[i]-97].front());
        dex[asli[i]-97].pop_front();
    }
    int jwbn=0;
    for(int i=0; i<n; i++) {
        jwbn+=quer(1,0,n-1,isi[i],n-1);
        update(1,0,n-1,isi[i]);
    }
    cout << jwbn << endl;
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:36:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for(int i=0; i<asli.size(); i++) {
      |                  ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 16 ms 2060 KB Output is correct
3 Correct 32 ms 3920 KB Output is correct
4 Incorrect 51 ms 4564 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 16 ms 2060 KB Output is correct
3 Correct 32 ms 3920 KB Output is correct
4 Incorrect 51 ms 4564 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 16 ms 2060 KB Output is correct
3 Correct 32 ms 3920 KB Output is correct
4 Incorrect 51 ms 4564 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 232 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 16 ms 2060 KB Output is correct
3 Correct 32 ms 3920 KB Output is correct
4 Incorrect 51 ms 4564 KB Output isn't correct
5 Halted 0 ms 0 KB -