답안 #603212

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
603212 2022-07-23T17:11:07 Z Abdulmohsen1284 Arranging Shoes (IOI19_shoes) C++14
10 / 100
1 ms 316 KB
#include"bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class x>
using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void usaco(){freopen("cruise.out","w",stdout);freopen("cruise.in","r",stdin);}


#include "shoes.h"
long long ls[100005],rs[100005],seg[4000005],l,r,N=1;
bool used[100005];

long long lef(long long fr,long long sc,long long ind)
{
    if(l<=fr&&r>=sc)
        return seg[ind];
    if(r<fr||sc<l)
        return 0;
    long long mid=fr+sc;
    mid/=2;
    return lef(fr,mid,ind*2)+lef(mid+1,sc,ind*2+1);
}

long long count_swaps(std::vector<int> s) {
    long long n=s.size()/2;
    while(N<s.size())
        N*=2;
    long long sum=0;
    //cout<<"YO"<<endl;
    for(int i=N;i<N+s.size();i++)
        seg[i]=1;
    for(int i=N-1;i>=1;i--)
        seg[i]=seg[i*2]+seg[i*2+1];

    for(int i=0;i<s.size();i++)
    {
        if(s[i]<0)
            ls[s[i]*-1]=i;
        else
            rs[s[i]]=i;
    }
    //cout<<"YO"<<endl;
    for(int i=0;i<s.size();i++)
    {
        if(!used[max(s[i]*-1,s[i])])
        {
            if(s[i]<0)
            {
                l=i+2;
                r=rs[s[i]*-1];
                sum+=lef(1,N,1);
            }
            else{
                l=i+1;
                r=ls[s[i]];
                sum+=lef(1,N,1);
            }
            long long cur=r+N-1;
            seg[cur]=0;
            while(cur>1)
            {
                cur/=2;
                seg[cur]=seg[cur*2]+seg[cur*2+1];
            }
            used[max(s[i]*-1,s[i])]=true;
            //cout<<sum<<" ";
        }

    }
    return sum;
}

Compilation message

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:29:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     while(N<s.size())
      |           ~^~~~~~~~~
shoes.cpp:33:18: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
   33 |     for(int i=N;i<N+s.size();i++)
      |                 ~^~~~~~~~~~~
shoes.cpp:38:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for(int i=0;i<s.size();i++)
      |                 ~^~~~~~~~~
shoes.cpp:46:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for(int i=0;i<s.size();i++)
      |                 ~^~~~~~~~~
shoes.cpp:28:15: warning: unused variable 'n' [-Wunused-variable]
   28 |     long long n=s.size()/2;
      |               ^
shoes.cpp: In function 'void usaco()':
shoes.cpp:9:21: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 | void usaco(){freopen("cruise.out","w",stdout);freopen("cruise.in","r",stdin);}
      |              ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
shoes.cpp:9:54: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 | void usaco(){freopen("cruise.out","w",stdout);freopen("cruise.in","r",stdin);}
      |                                               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Incorrect 1 ms 212 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 312 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Incorrect 1 ms 212 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Incorrect 1 ms 212 KB Output isn't correct
15 Halted 0 ms 0 KB -