1 #include<iostream>
2 #include<cstdio>
3 #include<cstdlib>
4 #include<cmath>
5 #include<cstring>
6 using namespace std;
7 const int maxn=1e6+10;
8
9 struct node
10 {
11 int l;
12 int r;
13 int value;
14 int lazy;
15 }tree[maxn];
16 int q;
17 struct tre
18 {
19 int a,b,c;
20 }o[maxn];
21 int n,m;
22 int lllll;
23 int a[maxn];
24 void pushup(int x)
25 {
26 tree[x].value=tree[x<<1].value+tree[x<<1|1].value;
27 }
28
29 void pushdown(int x)
30 {
31 if(tree[x].lazy!=-1)
32 {
33 tree[x<<1].lazy=tree[x].lazy;
34 tree[x<<1|1].lazy=tree[x].lazy;
35 tree[x<<1].value=(tree[x<<1].r-tree[x<<1].l+1)*tree[x].lazy;
36 tree[x<<1|1].value=(tree[x<<1|1].r-tree[x<<1|1].l+1)*tree[x].lazy;
37 tree[x].lazy=-1;
38 }
39 if(tree[x].l<tree[x].r)
40 {
41 pushup(x);
42 }
43 }
44 void build(int x,int l,int r)
45 {
46 tree[x].l=l;
47 tree[x].r=r;
48 tree[x].lazy=-1;
49 if(l==r)
50 {
51 tree[x].value=a[l]>lllll;
52 return ;
53 }
54 int mid=(l+r)>>1;
55 build(x<<1,l,mid);
56 build(x<<1|1,mid+1,r);
57 pushup(x);
58 }
59 int query(int x,int ls,int rs)
60 {
61 int l=tree[x].l;
62 int r=tree[x].r;
63 int mid=(l+r)>>1;
64 pushdown(x);
65 if(ls<=l&&r<=rs)
66 {
67 return tree[x].value;
68 }
69 int ans=0;
70 if(ls<=mid)
71 {
72 ans+=query(x<<1,ls,rs);
73 }
74 if(rs>mid)
75 {
76 ans+=query(x<<1|1,ls,rs);
77 }
78 return ans;
79 }
80 void modify(int x,int ls,int rs,int c)
81 {
82 int l=tree[x].l;
83 int r=tree[x].r;
84 int mid=(l+r)>>1;
85 pushdown(x);
86 if(ls<=l&&r<=rs)
87 {
88 tree[x].value=(r-l+1)*c;
89 tree[x].lazy=c;
90 return ;
91 }
92 if(ls<=mid)
93 {
94 modify(x<<1,ls,rs,c);
95
96 }
97 if(rs>mid)
98 {
99 modify(x<<1|1,ls,rs,c);
100 }
101 pushup(x);
102 }
103 bool check(int x)
104 {
105 lllll=x;
106 build(1,1,n);
107 for(int i=1;i<=m;i++)
108 {
109 int opt=o[i].a;
110 int x=o[i].b;
111 int y=o[i].c;
112 int tmp=query(1,x,y);
113 if (opt == 0)
114 {
115 modify(1,x,y-tmp,0);
116 modify(1,y-tmp+1,y,1);
117 }
118 else
119 {
120 modify(1,x,x+tmp-1,1);
121 modify(1,x+tmp,y,0);
122 }
123 }
124 return !query(1,q,q);
125 }
126 int main()
127 {
128 cin>>n>>m;
129 for(int i=1;i<=n;i++)
130 {
131 cin>>a[i];
132 }
133 for(int i=1;i<=m;i++)
134 {
135 cin>>o[i].a>>o[i].b>>o[i].c;
136 }
137 cin>>q;
138 int l=1;
139 int r=n;
140 while(l<r)
141 {
142 int mid=l+(r-l)/2;
143 if(check(mid))
144 {
145 r=mid;
146 }
147 else
148 {
149 l=mid+1;
150 }
151 }
152 cout<<r<<endl;
153 return 0;
154 }