답안 #709728

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
709728 2023-03-14T09:26:03 Z groshi Election (BOI18_election) C++17
100 / 100
568 ms 27640 KB
#include<iostream>
#include<algorithm>
using namespace std;
pair<pair<int,int>,pair<int,int> > drzewo[2000000];///0 -> suma, 1 -> lewo, 2 -> prawo, 3 -> wynik
int pot=1;
pair<pair<int,int>,pair<int,int> > lacz(pair<pair<int,int>,pair<int,int> > a,pair<pair<int,int>,pair<int,int> > b)
{
    pair<pair<int,int>,pair<int,int> > para={{0,0},{0,0}};
    para.first.first=a.first.first+b.first.first;
    para.first.second=max(a.first.second,a.first.first+b.first.second);
    para.second.first=max(b.second.first,b.first.first+a.second.first);
    para.second.second=max({a.first.second+b.second.first,a.first.first+b.second.second,a.second.second+b.first.first});
    return para;
}
pair<pair<int,int>,pair<int,int> > zapp(int x,int l,int r,int a,int b)
{
    if(l>b || r<a)
        return {{0,0},{0,0}};
    if(a<=l && r<=b)
        return drzewo[x];
    int mid=(l+r)/2;
    auto mam1=zapp(x*2,l,mid,a,b);
    auto mam2=zapp(x*2+1,mid+1,r,a,b);
    return lacz(mam1,mam2);
}
int32_t main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    int n,x,y;
    cin>>n;
    string s;
    cin>>s;
    while(pot<=n)
        pot*=2;
    pot--;
    for(int i=0;i<n;i++)
        if(s[i]=='T')
            drzewo[i+pot+1].first.first=drzewo[i+pot+1].first.second=drzewo[i+pot+1].second.first=drzewo[i+pot+1].second.second=1;
        else drzewo[i+pot+1].first.first=-1;
    for(int i=pot;i>=1;i--)
        drzewo[i]=lacz(drzewo[i*2],drzewo[i*2+1]);
    int zap;
    cin>>zap;
    while(zap--)
    {
        int x,y;
        cin>>x>>y;
        cout<<zapp(1,pot+1,pot*2+1,x+pot,y+pot).second.second<<"\n";
    }
    return 0;
}

Compilation message

election.cpp: In function 'int32_t main()':
election.cpp:31:11: warning: unused variable 'x' [-Wunused-variable]
   31 |     int n,x,y;
      |           ^
election.cpp:31:13: warning: unused variable 'y' [-Wunused-variable]
   31 |     int n,x,y;
      |             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 51 ms 4764 KB Output is correct
7 Correct 52 ms 4832 KB Output is correct
8 Correct 63 ms 4700 KB Output is correct
9 Correct 43 ms 4684 KB Output is correct
10 Correct 46 ms 4668 KB Output is correct
11 Correct 49 ms 4892 KB Output is correct
12 Correct 50 ms 4876 KB Output is correct
13 Correct 55 ms 4872 KB Output is correct
14 Correct 54 ms 4812 KB Output is correct
15 Correct 46 ms 4812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 51 ms 4764 KB Output is correct
7 Correct 52 ms 4832 KB Output is correct
8 Correct 63 ms 4700 KB Output is correct
9 Correct 43 ms 4684 KB Output is correct
10 Correct 46 ms 4668 KB Output is correct
11 Correct 49 ms 4892 KB Output is correct
12 Correct 50 ms 4876 KB Output is correct
13 Correct 55 ms 4872 KB Output is correct
14 Correct 54 ms 4812 KB Output is correct
15 Correct 46 ms 4812 KB Output is correct
16 Correct 456 ms 26608 KB Output is correct
17 Correct 391 ms 26080 KB Output is correct
18 Correct 434 ms 26460 KB Output is correct
19 Correct 392 ms 26056 KB Output is correct
20 Correct 485 ms 25632 KB Output is correct
21 Correct 476 ms 27404 KB Output is correct
22 Correct 438 ms 27340 KB Output is correct
23 Correct 516 ms 27640 KB Output is correct
24 Correct 488 ms 27396 KB Output is correct
25 Correct 568 ms 26780 KB Output is correct