답안 #285522

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
285522 2020-08-29T07:57:41 Z lukameladze Mountains (NOI20_mountains) C++14
100 / 100
539 ms 15384 KB
# include <bits/stdc++.h>
using namespace std;
long long tree[1000005],j,n,ans,x,y,id,fix[300005],raod;
pair <long long , long long > a[300005];
vector <long long> v;
void inc(int idx, int val)
{
    for (int i=idx; i<=n; i+=i&(-i))
    {
        tree[i]+=val;
    }
}
long long getans (int idx)
{
    long  long pas=0;
    for (int i=idx; i>0; i-=i&(-i))
    {
        pas+=tree[i];
    }
    return pas;
}
int main()
{
    cin>>n;
    for (int i=1; i<=n; i++)
    {
        cin>>a[i].first;
        a[i].second=i;
    }
    sort(a+1,a+n+1);
    for (int i=1; i<=n; i++)
    {
        if(a[i].first!=a[i-1].first) 
        fix[a[i].second]=1;//cout<<i<<" ";
    }
   // cout<<endl;
    inc(a[1].second,1);
    j=n+1;
    for (long long i=2; i<=n; i++)
    {
        if (fix[a[i].second]==1) 
        { j=i; break;}
        inc(a[i].second,1);
    }
    
    //cout<<j<<endl;
    for (long long i=j; i<=n; i++)
    {
        raod++;
        id=a[i].second;
        v.push_back(a[i].second);
        x=getans(id-1);
        y=getans(n)-getans(id);
       // cout<<id<<" "<<x<<" "<<y<<" "<<x*y<<endl;
        ans+=x*y;
        if (fix[a[i+1].second]==1)
        {
            for (int x=0; x<v.size(); x++)
            {
                inc(v[x], 1);
            }
            v.clear();
        }
        
      //  inc(a[i].second,raod);
        raod=0;
    }
    cout<<ans<<endl;
}

Compilation message

Mountains.cpp: In function 'int main()':
Mountains.cpp:58:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |             for (int x=0; x<v.size(); x++)
      |                           ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 488 ms 9660 KB Output is correct
3 Correct 468 ms 9804 KB Output is correct
4 Correct 473 ms 9696 KB Output is correct
5 Correct 463 ms 9720 KB Output is correct
6 Correct 468 ms 9728 KB Output is correct
7 Correct 472 ms 9824 KB Output is correct
8 Correct 474 ms 9720 KB Output is correct
9 Correct 480 ms 9720 KB Output is correct
10 Correct 479 ms 9720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 9544 KB Output is correct
2 Correct 137 ms 9584 KB Output is correct
3 Correct 124 ms 9580 KB Output is correct
4 Correct 122 ms 9528 KB Output is correct
5 Correct 127 ms 9584 KB Output is correct
6 Correct 120 ms 9580 KB Output is correct
7 Correct 121 ms 9580 KB Output is correct
8 Correct 101 ms 8428 KB Output is correct
9 Correct 108 ms 8428 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 9544 KB Output is correct
2 Correct 137 ms 9584 KB Output is correct
3 Correct 124 ms 9580 KB Output is correct
4 Correct 122 ms 9528 KB Output is correct
5 Correct 127 ms 9584 KB Output is correct
6 Correct 120 ms 9580 KB Output is correct
7 Correct 121 ms 9580 KB Output is correct
8 Correct 101 ms 8428 KB Output is correct
9 Correct 108 ms 8428 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 157 ms 7416 KB Output is correct
12 Correct 167 ms 8312 KB Output is correct
13 Correct 161 ms 8440 KB Output is correct
14 Correct 158 ms 8312 KB Output is correct
15 Correct 172 ms 8312 KB Output is correct
16 Correct 160 ms 8312 KB Output is correct
17 Correct 162 ms 8312 KB Output is correct
18 Correct 133 ms 8696 KB Output is correct
19 Correct 132 ms 8696 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 17 ms 896 KB Output is correct
12 Correct 19 ms 768 KB Output is correct
13 Correct 17 ms 896 KB Output is correct
14 Correct 20 ms 892 KB Output is correct
15 Correct 22 ms 896 KB Output is correct
16 Correct 17 ms 888 KB Output is correct
17 Correct 17 ms 896 KB Output is correct
18 Correct 17 ms 896 KB Output is correct
19 Correct 6 ms 640 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 9544 KB Output is correct
2 Correct 137 ms 9584 KB Output is correct
3 Correct 124 ms 9580 KB Output is correct
4 Correct 122 ms 9528 KB Output is correct
5 Correct 127 ms 9584 KB Output is correct
6 Correct 120 ms 9580 KB Output is correct
7 Correct 121 ms 9580 KB Output is correct
8 Correct 101 ms 8428 KB Output is correct
9 Correct 108 ms 8428 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 157 ms 7416 KB Output is correct
12 Correct 167 ms 8312 KB Output is correct
13 Correct 161 ms 8440 KB Output is correct
14 Correct 158 ms 8312 KB Output is correct
15 Correct 172 ms 8312 KB Output is correct
16 Correct 160 ms 8312 KB Output is correct
17 Correct 162 ms 8312 KB Output is correct
18 Correct 133 ms 8696 KB Output is correct
19 Correct 132 ms 8696 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 260 ms 11576 KB Output is correct
22 Correct 246 ms 11384 KB Output is correct
23 Correct 247 ms 11544 KB Output is correct
24 Correct 240 ms 11384 KB Output is correct
25 Correct 252 ms 11512 KB Output is correct
26 Correct 244 ms 11384 KB Output is correct
27 Correct 241 ms 11384 KB Output is correct
28 Correct 198 ms 11512 KB Output is correct
29 Correct 202 ms 11456 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 488 ms 9660 KB Output is correct
3 Correct 468 ms 9804 KB Output is correct
4 Correct 473 ms 9696 KB Output is correct
5 Correct 463 ms 9720 KB Output is correct
6 Correct 468 ms 9728 KB Output is correct
7 Correct 472 ms 9824 KB Output is correct
8 Correct 474 ms 9720 KB Output is correct
9 Correct 480 ms 9720 KB Output is correct
10 Correct 479 ms 9720 KB Output is correct
11 Correct 123 ms 9544 KB Output is correct
12 Correct 137 ms 9584 KB Output is correct
13 Correct 124 ms 9580 KB Output is correct
14 Correct 122 ms 9528 KB Output is correct
15 Correct 127 ms 9584 KB Output is correct
16 Correct 120 ms 9580 KB Output is correct
17 Correct 121 ms 9580 KB Output is correct
18 Correct 101 ms 8428 KB Output is correct
19 Correct 108 ms 8428 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 157 ms 7416 KB Output is correct
22 Correct 167 ms 8312 KB Output is correct
23 Correct 161 ms 8440 KB Output is correct
24 Correct 158 ms 8312 KB Output is correct
25 Correct 172 ms 8312 KB Output is correct
26 Correct 160 ms 8312 KB Output is correct
27 Correct 162 ms 8312 KB Output is correct
28 Correct 133 ms 8696 KB Output is correct
29 Correct 132 ms 8696 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 0 ms 384 KB Output is correct
41 Correct 17 ms 896 KB Output is correct
42 Correct 19 ms 768 KB Output is correct
43 Correct 17 ms 896 KB Output is correct
44 Correct 20 ms 892 KB Output is correct
45 Correct 22 ms 896 KB Output is correct
46 Correct 17 ms 888 KB Output is correct
47 Correct 17 ms 896 KB Output is correct
48 Correct 17 ms 896 KB Output is correct
49 Correct 6 ms 640 KB Output is correct
50 Correct 0 ms 384 KB Output is correct
51 Correct 260 ms 11576 KB Output is correct
52 Correct 246 ms 11384 KB Output is correct
53 Correct 247 ms 11544 KB Output is correct
54 Correct 240 ms 11384 KB Output is correct
55 Correct 252 ms 11512 KB Output is correct
56 Correct 244 ms 11384 KB Output is correct
57 Correct 241 ms 11384 KB Output is correct
58 Correct 198 ms 11512 KB Output is correct
59 Correct 202 ms 11456 KB Output is correct
60 Correct 1 ms 384 KB Output is correct
61 Correct 505 ms 15224 KB Output is correct
62 Correct 503 ms 15352 KB Output is correct
63 Correct 507 ms 15224 KB Output is correct
64 Correct 509 ms 15384 KB Output is correct
65 Correct 510 ms 15352 KB Output is correct
66 Correct 512 ms 15224 KB Output is correct
67 Correct 534 ms 15288 KB Output is correct
68 Correct 539 ms 15352 KB Output is correct
69 Correct 259 ms 11512 KB Output is correct
70 Correct 1 ms 384 KB Output is correct