#P11146. 「SFMOI Round I」Strange Train Game

    ID: 10438 远端评测题 1000ms 500MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>贪心并查集洛谷原创O2优化图论建模线性基随机化洛谷月赛

「SFMOI Round I」Strange Train Game

Description

Hint: A brief and formalized statement is provided at the end of the description.

A train called SFM consists of nn carriages, numbered from 11 to nn. Carriage indexed ii has comfort ai{0,1}a_i\in \{0,1\}, where 11 stands for comfortable, and 00 stands for uncomfortable. We want to minimize the indices of comfortable carriages, in other words, to maximize the lexicographical order of aa.

In order to do that, we have another train consists also nn carriages, whose comfortable numbers are denoted by bi{0,1}b_i\in \{0,1\}. There are mm operations available, the ii-th operation has two parameters li,ril_i,r_i, which denotes swapping aka_k and bkb_k for every k[li,ri]k\in [l_i,r_i].

You can choose to perform or not to perform the operations in a given order. There are 2m2^m ways to do that, so we turned to you to choose the best one to maximize the lexicographical order of aa. You only need to output the final result.

Formally: Two binary string a,ba,b are given, whose length are both nn. Also, 2m2m integers li,ril_i,r_i is given. For i=1,2,,mi=1,2,\ldots,m, by this order, excecute the precedure:

  • Choose to perform ii-th operation or not.
    • If so, for k=li,li+1,,rik=l_i,l_i+1,\cdots,r_i, swap aka_k and bkb_k.

You need to maximize the lexicographical order of aa and output the final result.

Input Format

The first line contains two integers n,mn,m—the number of carriages and the number of operations, respectively.

The second line contains a binary string aa, where aia_i is the comfort of the train SFM.

The second line contains a binary string bb, where bib_i is the comfort of another train.

The following mm lines, the ii-th line contains two integers li,ril_i,r_i, to describe the ii-th operation.

Output Format

Output one line containing a binary string—the best result after the operations.

10 5
0101011001
0101001110
5 10
2 6
1 10
6 6
3 4
0101011110

Hint

本题采用捆绑测试。

  • Subtask 1 (20 pts): 1n,m201\le n,m\le 20;
  • Subtask 2 (30 pts):lil_i are pairwise distinct, aibia_i \ne b_i;
  • Subtask 3 (30 pts):1n,m1031 \le n ,m \le 10^3;
  • Subtask 4 (20 pts):No further constraints.

It is guaranteed that

  • 1n,m2×1051\le n,m\le 2\times 10^5;
  • 1lirin1\le l_i\le r_i\le n.