Submission #1098317

# Submission time Handle Problem Language Result Execution time Memory
1098317 2024-10-09T09:31:38 Z modwwe None (JOI16_matryoshka) C++17
100 / 100
256 ms 18844 KB
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC optimize("conserve-stack")
#include<bits/stdc++.h>
//#define int long long
#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#define NHP     ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe  int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define pb push_back
#define checktime   cerr << (double)clock() / CLOCKS_PER_SEC * 1000  << " ms";
using namespace std;
#define getchar_unlocked getchar

inline int scan()
{
    char c = getchar_unlocked();
    int x = 0;
    while (c < '0' || c > '9')
    {
        c = getchar_unlocked();
    }
    while (c >= '0' && c <= '9')
    {
        x = (x << 1) + (x << 3) + c - '0';
        c = getchar_unlocked();
    }
    return x;
}

void phongbeo();
const int inf = 1e18;
const int mod2 = 1e9 + 7;
const int  mod1 = 998244353;
struct icd
{
    long double a;
    int b;
};
struct ib
{
    int a;
    int b;
};
struct ic
{
    int a, b, c;
};
struct id
{
    int a, b, c, d;
};
struct ie
{
    int a, b, c, d, e;

};

int n, m, s1, s2, s4, s3, sf, k, s5, s6, mx, s7, s8, s9, mx2, res, dem2 = 0, dem = 0, s33, dem3, dem4, l, r, mid, l2, r2, center;
int  i, s10, s12,k1,k2,k3,s11,t,lim,w;
int kk;
int el = 19;

main()
{
    if(fopen(task".inp","r"))
    {
        fin(task);
        fou(task);
    }
    NHP
    /// cin>>s1;
///modwwe
    phongbeo();
    // checktime
}
ib a[200001];
ic b[200001];
int ans[200001];
vector<int> v;
bool cmp(ib a,ib b)
{
    if(a.b==b.b) return a.a>b.a;
    return a.b<b.b;
}
bool  cmp2(ic a,ic b)
{
    return a.b<b.b;
}
struct seg
{
    ib t[800001];
    void upd(int node,int l,int r,int l1,int x)
    {
        if(l==r)
        {
            t[node].a+=x;
            if(t[node].a!=0) t[node].b=l;
            else t[node].b=0;
            return;
        }
        int mid=l+r>>1;
        if(l1<=mid)
            upd(node<<1,l,mid,l1,x);
        else upd(node<<1|1,mid+1,r,l1,x);
        t[node].b=max(t[node<<1].b,t[node<<1|1].b);
        t[node].a=t[node<<1].a+t[node<<1|1].a;
    }
    int get(int node,int l,int r,int l1,int r1)
    {
        if(l>r1||r<l1) return 0;
        if(l>=l1&&r<=r1) return t[node].b;
        int mid=l+r>>1;
        return  max(get(node<<1,l,mid,l1,r1),get(node<<1|1,mid+1,r,l1,r1));
    }
    int get2(int node,int l,int r,int l1,int r1 )
    {
        if(l1>r1) return 0;
        if(l>r1||r<l1) return 0;
        if(l>=l1&&r<=r1) return t[node].a;
        int mid=l+r>>1;
        return get2(node<<1,l,mid,l1,r1)+get2(node<<1|1,mid+1,r,l1,r1);
    }
} st;
void upd(int x)
{
    s3=st.get(1,1,n,1,a[x].a-1);
    if(s3!=0)
        st.upd(1,1,n,s3,-1);
    st.upd(1,1,n,a[x].a,1) ;

}
void phongbeo()
{
    cin>>n>>m;
    for(int i=1; i<=n; i++)
        cin>>a[i].a>>a[i].b,v.pb(a[i].a);
    sort(a+1,a+1+n,cmp);
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    for(int i=1; i<=n; i++)
        a[i].a=lower_bound(v.begin(),v.end(),a[i].a)-v.begin()+1;
    for(int i=1; i<=m; i++)
        cin>>b[i].a>>b[i].b,b[i].c=i;
    sort(b+1,b+1+m,cmp2);
    l=1;
    s11=n;
    n=v.size();
    for(int i=1; i<=m; i++)
    {
        while(l<=s11&&a[l].b<=b[i].b)
        {
            upd(l);
            l++;
        }
        s2=lower_bound(v.begin(),v.end(),b[i].a)-v.begin()+1;
        ans[b[i].c]=st.get2(1,1,n,s2,n);
    }
    for(int i=1; i<=m; i++)
        cout<<ans[i],down
    }

Compilation message

matryoshka.cpp:37:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   37 | const int inf = 1e18;
      |                 ^~~~
matryoshka.cpp:69:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   69 | main()
      | ^~~~
matryoshka.cpp: In member function 'void seg::upd(int, int, int, int, int)':
matryoshka.cpp:107:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  107 |         int mid=l+r>>1;
      |                 ~^~
matryoshka.cpp: In member function 'int seg::get(int, int, int, int, int)':
matryoshka.cpp:118:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  118 |         int mid=l+r>>1;
      |                 ~^~
matryoshka.cpp: In member function 'int seg::get2(int, int, int, int, int)':
matryoshka.cpp:126:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  126 |         int mid=l+r>>1;
      |                 ~^~
matryoshka.cpp: In function 'int main()':
matryoshka.cpp:13:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 | #define fin(x) freopen(x".inp","r",stdin)
      |                ~~~~~~~^~~~~~~~~~~~~~~~~~~
matryoshka.cpp:73:9: note: in expansion of macro 'fin'
   73 |         fin(task);
      |         ^~~
matryoshka.cpp:14:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 | #define fou(x) freopen(x".out","w",stdout)
      |                ~~~~~~~^~~~~~~~~~~~~~~~~~~~
matryoshka.cpp:74:9: note: in expansion of macro 'fou'
   74 |         fou(task);
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 2 ms 604 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 2 ms 488 KB Output is correct
26 Correct 2 ms 600 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 2 ms 348 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 2 ms 600 KB Output is correct
33 Correct 2 ms 604 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 2 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 2 ms 604 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 2 ms 488 KB Output is correct
26 Correct 2 ms 600 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 2 ms 348 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 2 ms 600 KB Output is correct
33 Correct 2 ms 604 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 2 ms 600 KB Output is correct
36 Correct 245 ms 16036 KB Output is correct
37 Correct 217 ms 15232 KB Output is correct
38 Correct 82 ms 7008 KB Output is correct
39 Correct 114 ms 9616 KB Output is correct
40 Correct 120 ms 10128 KB Output is correct
41 Correct 224 ms 15312 KB Output is correct
42 Correct 71 ms 8656 KB Output is correct
43 Correct 51 ms 8908 KB Output is correct
44 Correct 255 ms 18640 KB Output is correct
45 Correct 256 ms 18636 KB Output is correct
46 Correct 255 ms 18644 KB Output is correct
47 Correct 231 ms 18124 KB Output is correct
48 Correct 223 ms 18844 KB Output is correct
49 Correct 225 ms 18140 KB Output is correct
50 Correct 218 ms 18844 KB Output is correct