Submission #18948383


Source Code Expand

Copy
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 200005;
int seg[4*N];
int S = 0,E = N;
int insert(int num,int s=S,int e=E,int p=1)
{
    seg[p]++;
    if(s==e)
        return seg[p];
    int mid = (s+e)>>1;
    if(num<=mid)
        return insert(num,s,mid,2*p);
    return seg[2*p] + insert(num,mid+1,e,2*p+1);
}
int get(int num,int s=S,int e=E,int p=1)
{
    if(s==e)
        return seg[p];
    int mid = (s+e)>>1;
    if(num<=mid)
        return get(num,s,mid,2*p);
    return seg[2*p] + get(num,mid+1,e,2*p+1);
}
void solve()
{
    int h, w, m;
    cin>>h>>w>>m;
    vector<pair<int,int>> v(m);
    for(int i=0;i<m;i++)
    {
        cin>>v[i].first>>v[i].second;
        v[i].first--;
        v[i].second--;
    }
    sort(v.begin(),v.end());

    vector<vector<int>> by_row(h), by_col(w);
    for (auto &it : v)
    {
        by_row[it.first].push_back(it.second);
        by_col[it.second].push_back(it.first);
    }
    for (int x = 0; x < h; x++)
        by_row[x].push_back(w);
    for (int y = 0; y < w; y++)
        by_col[y].push_back(h);

    int reachable_rows = by_col[0].front();
    int reachable_cols = by_row[0].front();

    ll ans = 0;
    for (int x = 0; x < reachable_rows; x++)
        ans += by_row[x].front();
    for (int y = 1; y < reachable_cols; y++)
    {
        int height = by_col[y].front();

        ans += max(0, height - reachable_rows);

        int x = min(reachable_rows, height);
        ans += get(x-1);

       // cout<<y<<' '<<get(x-1)<<endl;

        for (int x : by_col[y])
            insert(x);
    }
    cout<<ans<<'\n';
}
int main()
{
    ios_base::sync_with_stdio(false),cin.tie(0);
    solve();
    return 0;
}

Submission Info

Submission Time
Task F - Rook on Grid
User Khaled__Mahmoud
Language C++ (GCC 9.2.1)
Score 0
Code Size 1774 Byte
Status WA
Exec Time 170 ms
Memory 28896 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 600
Status
AC × 3
AC × 18
WA × 11
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
hand_01.txt AC 51 ms 24472 KB
hand_02.txt AC 49 ms 25036 KB
hand_03.txt AC 26 ms 14092 KB
hand_04.txt AC 22 ms 14096 KB
hand_05.txt AC 2 ms 3572 KB
hand_06.txt AC 4 ms 3544 KB
random_01.txt WA 157 ms 28612 KB
random_02.txt WA 114 ms 28664 KB
random_03.txt WA 122 ms 28796 KB
random_04.txt WA 170 ms 28688 KB
random_05.txt WA 157 ms 28860 KB
random_06.txt WA 133 ms 28708 KB
random_07.txt WA 126 ms 28896 KB
random_08.txt AC 49 ms 26712 KB
random_09.txt WA 51 ms 26748 KB
random_10.txt AC 52 ms 26692 KB
random_11.txt AC 54 ms 6876 KB
random_12.txt AC 52 ms 6736 KB
random_13.txt AC 55 ms 6836 KB
random_14.txt AC 56 ms 6704 KB
random_15.txt AC 52 ms 6872 KB
random_16.txt AC 54 ms 6672 KB
random_17.txt AC 54 ms 6820 KB
random_18.txt WA 3 ms 3712 KB
random_19.txt WA 3 ms 3696 KB
random_20.txt WA 2 ms 3716 KB
sample_01.txt AC 2 ms 3480 KB
sample_02.txt AC 2 ms 3480 KB
sample_03.txt AC 56 ms 25096 KB