답안 #991511

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
991511 2024-06-02T10:54:48 Z modwwe Fire (JOI20_ho_t5) C++17
100 / 100
484 ms 148956 KB
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
#include<bits/stdc++.h>
#define int long long
///#define ll long long
#define down cout<<'\n';
#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;
void phongbeo();
const int mod2=998244353;
const int  mod1=998244353;
struct icd
{
    int a,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,f;
 
};
int n,m,s1,s2,s4,s3,sf,k,r,mid,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,l;
int  i,s10,s12;
int el=29;
main()
{
#ifndef ONLINE_JUDGE
///fin(task),fou(task);
#endif
    NHP
    /// cin>>s1;
    /// modwwe
    phongbeo();
}
vector<ic> v[200001];
vector<ic> v2[400001];
vector<ic> v3[400001];
int ans[200001];
int a[200001];
int b[200001];
int c[200001];
int o;
struct IT
{
     int t[1600009],lazy[1600009],sz[1600009];
     void ff(int x)
     {
         for(int i=x*2;i<=x*2+1;i++)
            t[i]+=lazy[x]*sz[i],
            lazy[i]+=lazy[x];
 lazy[x]=0;
     }
     void build(int node,int l,int r)
     { sz[node]=r-l+1;
         if(l==r){return;}
     int mid=l+r>>1;
      build(node<<1,l,mid);
       build(node<<1|1,mid+1,r);
     }
     void update(int node,int l,int r,int l1,int r1,int f)
     {
          if(l>r1||r<l1) return ;
          if(l>=l1&&r<=r1)
          {
               t[node]+=f*sz[node];
               lazy[node]+=f;
                return;
          }
          ff(node);
           int mid=l+r>>1;
            update(node<<1,l,mid,l1,r1,f);
            update(node<<1|1,mid+1,r,l1,r1,f);
            t[node]=t[node<<1]+t[node<<1|1];
     }
     int gett(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];
              ff(node);
              int mid=l+r>>1;
                return gett(node<<1,l,mid,l1,r1)+gett(node<<1|1,mid+1,r,l1,r1);
       }
       void upd(int l,int r,int f)
       {
            l+=o;
             r+=o;
             update(1,0,o+o,l,r,f);
       }
       int get(int l,int r)
       {
        l+=o;
        r+=o;
        return gett(1,0,o+o,l,r);
       }
}st1,st2;
void cf(int x,int y,int z)
{
 v2[0].pb({-o,y,a[y]});
 v3[0].pb({-o,y-1,-a[y]});
 s2=y-1-x;
 v2[s2].pb({-o,x,-a[y]});
 v3[s2].pb({-o,y-1,a[y]});
 s3=z-1-y;
v2[s3].pb({-o,y,-a[y]});
 v3[s3].pb({-o,z-1,a[y]});
s4=z-1-x;
v2[s4].pb({-o,x,a[y]});
v3[s4].pb({-o,z-1,-a[y]});
}
void phongbeo()
{
    cin>>n>>m;
    o=n;
     for(int i=1;i<=n;i++)
          cin>>a[i];
     for(int i=1;i<=m;i++)
     {
           cin>>s2>>s3>>s4;
            v[s2].pb({s3,s4,i});
     }
      vector<int> stk;
	for(int i=n;i>=1;i--) {
		while(!stk.empty() && a[stk.back()]<=a[i]) stk.pop_back();
		if(stk.size()) {
			c[i]=stk.back();
		} else {
			c[i]=n+1;
		}
		stk.push_back(i);
	}
 
	stk.clear();
 
	for(int i=1;i<=n;i++) {
		while(!stk.empty() && a[stk.back()]<a[i]) stk.pop_back();
		if(stk.size()) {
			b[i]=stk.back();
		} else {
			b[i]=-o;
		}
		stk.push_back(i);
	}
	for(int i=1;i<=n;i++)
    { //cout<<b[i]<<" "<<i<<" "<<c[i],down
         cf(b[i],i,c[i]);
    }
    st1.build(1,0,o+o);
    st2.build(1,0,o+o);
    for(int i=0;i<=n;i++)
    {
         for(auto x:v2[i]){
          st1.upd(x.a,x.b,x.c);
         /// if(i==0)
           ///  cout<<x.a<<" "<<x.b<<" "<<x.c<<" goku",down
          }
         for(auto x:v3[i]){
         st2.upd(x.a,x.b,x.c);
              ///   if(i==0)
             ///cout<<x.a<<" "<<x.b<<" "<<x.c<<" cuto",down
         }
         for(auto x:v[i])
            ans[x.c]=st1.get(x.a-i,x.b-i)+st2.get(x.a,x.b);
    }
    for(int i=1;i<=m;i++)
    {
      cout<<ans[i],down
    }
 
}

Compilation message

ho_t5.cpp:45:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   45 | main()
      | ^~~~
ho_t5.cpp: In member function 'void IT::build(long long int, long long int, long long int)':
ho_t5.cpp:76:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   76 |      int mid=l+r>>1;
      |              ~^~
ho_t5.cpp: In member function 'void IT::update(long long int, long long int, long long int, long long int, long long int, long long int)':
ho_t5.cpp:90:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   90 |            int mid=l+r>>1;
      |                    ~^~
ho_t5.cpp: In member function 'long long int IT::gett(long long int, long long int, long long int, long long int, long long int)':
ho_t5.cpp:100:24: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  100 |               int mid=l+r>>1;
      |                       ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 37468 KB Output is correct
2 Correct 8 ms 35416 KB Output is correct
3 Correct 8 ms 35420 KB Output is correct
4 Correct 7 ms 35420 KB Output is correct
5 Correct 7 ms 35360 KB Output is correct
6 Correct 7 ms 35420 KB Output is correct
7 Correct 8 ms 35420 KB Output is correct
8 Correct 8 ms 35420 KB Output is correct
9 Correct 7 ms 35416 KB Output is correct
10 Correct 7 ms 35416 KB Output is correct
11 Correct 7 ms 35380 KB Output is correct
12 Correct 7 ms 35556 KB Output is correct
13 Correct 7 ms 35420 KB Output is correct
14 Correct 7 ms 35420 KB Output is correct
15 Correct 7 ms 35420 KB Output is correct
16 Correct 7 ms 35420 KB Output is correct
17 Correct 7 ms 35560 KB Output is correct
18 Correct 7 ms 35420 KB Output is correct
19 Correct 7 ms 35420 KB Output is correct
20 Correct 7 ms 35420 KB Output is correct
21 Correct 7 ms 35512 KB Output is correct
22 Correct 7 ms 35420 KB Output is correct
23 Correct 7 ms 35356 KB Output is correct
24 Correct 7 ms 35420 KB Output is correct
25 Correct 7 ms 35420 KB Output is correct
26 Correct 7 ms 35376 KB Output is correct
27 Correct 8 ms 35420 KB Output is correct
28 Correct 8 ms 35560 KB Output is correct
29 Correct 7 ms 35420 KB Output is correct
30 Correct 7 ms 35548 KB Output is correct
31 Correct 7 ms 35420 KB Output is correct
32 Correct 7 ms 35420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 37468 KB Output is correct
2 Correct 398 ms 133796 KB Output is correct
3 Correct 403 ms 137128 KB Output is correct
4 Correct 441 ms 134828 KB Output is correct
5 Correct 421 ms 142680 KB Output is correct
6 Correct 414 ms 130732 KB Output is correct
7 Correct 417 ms 132264 KB Output is correct
8 Correct 392 ms 147108 KB Output is correct
9 Correct 419 ms 137640 KB Output is correct
10 Correct 439 ms 135084 KB Output is correct
11 Correct 444 ms 141996 KB Output is correct
12 Correct 401 ms 135032 KB Output is correct
13 Correct 403 ms 141732 KB Output is correct
14 Correct 410 ms 143024 KB Output is correct
15 Correct 441 ms 142124 KB Output is correct
16 Correct 442 ms 134828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 37468 KB Output is correct
2 Correct 396 ms 135096 KB Output is correct
3 Correct 387 ms 136912 KB Output is correct
4 Correct 443 ms 143032 KB Output is correct
5 Correct 414 ms 135044 KB Output is correct
6 Correct 425 ms 135068 KB Output is correct
7 Correct 420 ms 144856 KB Output is correct
8 Correct 403 ms 137896 KB Output is correct
9 Correct 402 ms 134864 KB Output is correct
10 Correct 408 ms 133768 KB Output is correct
11 Correct 430 ms 145548 KB Output is correct
12 Correct 388 ms 146564 KB Output is correct
13 Correct 457 ms 142288 KB Output is correct
14 Correct 379 ms 135660 KB Output is correct
15 Correct 413 ms 143536 KB Output is correct
16 Correct 408 ms 144528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 424 ms 135328 KB Output is correct
2 Correct 425 ms 136844 KB Output is correct
3 Correct 462 ms 137372 KB Output is correct
4 Correct 473 ms 138132 KB Output is correct
5 Correct 424 ms 137692 KB Output is correct
6 Correct 451 ms 136848 KB Output is correct
7 Correct 458 ms 135828 KB Output is correct
8 Correct 444 ms 135060 KB Output is correct
9 Correct 442 ms 137700 KB Output is correct
10 Correct 465 ms 139416 KB Output is correct
11 Correct 443 ms 136328 KB Output is correct
12 Correct 434 ms 134796 KB Output is correct
13 Correct 442 ms 135564 KB Output is correct
14 Correct 482 ms 137364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 37468 KB Output is correct
2 Correct 8 ms 35416 KB Output is correct
3 Correct 8 ms 35420 KB Output is correct
4 Correct 7 ms 35420 KB Output is correct
5 Correct 7 ms 35360 KB Output is correct
6 Correct 7 ms 35420 KB Output is correct
7 Correct 8 ms 35420 KB Output is correct
8 Correct 8 ms 35420 KB Output is correct
9 Correct 7 ms 35416 KB Output is correct
10 Correct 7 ms 35416 KB Output is correct
11 Correct 7 ms 35380 KB Output is correct
12 Correct 7 ms 35556 KB Output is correct
13 Correct 7 ms 35420 KB Output is correct
14 Correct 7 ms 35420 KB Output is correct
15 Correct 7 ms 35420 KB Output is correct
16 Correct 7 ms 35420 KB Output is correct
17 Correct 7 ms 35560 KB Output is correct
18 Correct 7 ms 35420 KB Output is correct
19 Correct 7 ms 35420 KB Output is correct
20 Correct 7 ms 35420 KB Output is correct
21 Correct 7 ms 35512 KB Output is correct
22 Correct 7 ms 35420 KB Output is correct
23 Correct 7 ms 35356 KB Output is correct
24 Correct 7 ms 35420 KB Output is correct
25 Correct 7 ms 35420 KB Output is correct
26 Correct 7 ms 35376 KB Output is correct
27 Correct 8 ms 35420 KB Output is correct
28 Correct 8 ms 35560 KB Output is correct
29 Correct 7 ms 35420 KB Output is correct
30 Correct 7 ms 35548 KB Output is correct
31 Correct 7 ms 35420 KB Output is correct
32 Correct 7 ms 35420 KB Output is correct
33 Correct 398 ms 133796 KB Output is correct
34 Correct 403 ms 137128 KB Output is correct
35 Correct 441 ms 134828 KB Output is correct
36 Correct 421 ms 142680 KB Output is correct
37 Correct 414 ms 130732 KB Output is correct
38 Correct 417 ms 132264 KB Output is correct
39 Correct 392 ms 147108 KB Output is correct
40 Correct 419 ms 137640 KB Output is correct
41 Correct 439 ms 135084 KB Output is correct
42 Correct 444 ms 141996 KB Output is correct
43 Correct 401 ms 135032 KB Output is correct
44 Correct 403 ms 141732 KB Output is correct
45 Correct 410 ms 143024 KB Output is correct
46 Correct 441 ms 142124 KB Output is correct
47 Correct 442 ms 134828 KB Output is correct
48 Correct 396 ms 135096 KB Output is correct
49 Correct 387 ms 136912 KB Output is correct
50 Correct 443 ms 143032 KB Output is correct
51 Correct 414 ms 135044 KB Output is correct
52 Correct 425 ms 135068 KB Output is correct
53 Correct 420 ms 144856 KB Output is correct
54 Correct 403 ms 137896 KB Output is correct
55 Correct 402 ms 134864 KB Output is correct
56 Correct 408 ms 133768 KB Output is correct
57 Correct 430 ms 145548 KB Output is correct
58 Correct 388 ms 146564 KB Output is correct
59 Correct 457 ms 142288 KB Output is correct
60 Correct 379 ms 135660 KB Output is correct
61 Correct 413 ms 143536 KB Output is correct
62 Correct 408 ms 144528 KB Output is correct
63 Correct 424 ms 135328 KB Output is correct
64 Correct 425 ms 136844 KB Output is correct
65 Correct 462 ms 137372 KB Output is correct
66 Correct 473 ms 138132 KB Output is correct
67 Correct 424 ms 137692 KB Output is correct
68 Correct 451 ms 136848 KB Output is correct
69 Correct 458 ms 135828 KB Output is correct
70 Correct 444 ms 135060 KB Output is correct
71 Correct 442 ms 137700 KB Output is correct
72 Correct 465 ms 139416 KB Output is correct
73 Correct 443 ms 136328 KB Output is correct
74 Correct 434 ms 134796 KB Output is correct
75 Correct 442 ms 135564 KB Output is correct
76 Correct 482 ms 137364 KB Output is correct
77 Correct 451 ms 135308 KB Output is correct
78 Correct 443 ms 138268 KB Output is correct
79 Correct 461 ms 147596 KB Output is correct
80 Correct 461 ms 139828 KB Output is correct
81 Correct 448 ms 137388 KB Output is correct
82 Correct 456 ms 143496 KB Output is correct
83 Correct 445 ms 135556 KB Output is correct
84 Correct 484 ms 136504 KB Output is correct
85 Correct 475 ms 146336 KB Output is correct
86 Correct 475 ms 135188 KB Output is correct
87 Correct 448 ms 146948 KB Output is correct
88 Correct 417 ms 146572 KB Output is correct
89 Correct 443 ms 139004 KB Output is correct
90 Correct 431 ms 146556 KB Output is correct
91 Correct 419 ms 138888 KB Output is correct
92 Correct 448 ms 136324 KB Output is correct
93 Correct 426 ms 137172 KB Output is correct
94 Correct 434 ms 148956 KB Output is correct
95 Correct 424 ms 145028 KB Output is correct
96 Correct 445 ms 137088 KB Output is correct
97 Correct 469 ms 140172 KB Output is correct
98 Correct 421 ms 132228 KB Output is correct
99 Correct 430 ms 137196 KB Output is correct
100 Correct 435 ms 140712 KB Output is correct
101 Correct 436 ms 133124 KB Output is correct
102 Correct 433 ms 143436 KB Output is correct